Feather: Use the Relative routes API
With Feather, 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 Feather 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. Feather 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 Feather convention-based routes are ignored.
For more information, see For developers: Autorouting in pure and hybrid mode and Feather: Implement master detail content controllers.
You can also read the following tutorial about working with attribute routing: Feather: Create a Books widget.