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 has the same constructors and properties as the stock
Route attribute. Sitefinity CMS automatically maps all routes defined, using the attributes for both
Route attributes. As a result, you do not need to call 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:
Displays the page and renders "This is Action1" on the place where the widget is located on the page.
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.