Configure routing for controller actions

With Sitefinity CMS, you can work with attribute routing in the context of Sitefinity CMS widgets. As a result of the integration with ASP.NET MVC 5, you can use the RelativeRoute attribute to work with attribute routing and attributes to define routes for controller actions.

NOTE: When using the RelativeRoute attribute on one of the controllers actions, all controller actions must be decorated with the attribute, as well. 

RelativeRoute attribute

The RelativeRoute attribute has the same constructors and properties as the stock Route attribute. Sitefinity CMS automatically maps all routes defined, using the attributes for both RelativeRoute and Route attributes. As a result, you do not need to call the MapMvcAttributeRoutes.

The Route attribute, describes routes relative to the application path. The RelativeRoute attribute, on the other hand, describes routes relative to the page node where the widget is placed.

This example illustrates the difference between the two attributes. You have the following widget implementation:

If you add this widget to a page with an URL ~/my-page, then you get two routes:

  • ~/my-page/my-sample-path
    Displays the page and renders "This is Action1" on the place where the widget is located on the page.
  • ~/my-sample-path
    Renders "This is Action2" as plain text.

NOTE: If there are any RelativeRoute attributes on your controller, then the default Sitefinity CMS autorouting handling and the convention-based routes are ignored.
For more information, see For developers: Autorouting in pure and hybrid mode and Implement Master Detail content controllers.

You can also read the following tutorial about working with attribute routing: Create a Book widget

 

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Tags

Was this article helpful?

Next article

Integrate Ninject