Interfaces

Project

Pages Html

NuGet packageOwin.Framework.Pages.Html
GitHub sourceOwinFramework.Pages.Html

Home |  Readme

[Route] attribute | The OWIN Framework Pages

The [Route] Attribute

The [Route] attribute adds an entry in the routing table that directs matching requests to this page. A page can have as many [Route] attributes as it likes, in which case you should consider specifying the canonical Url for the page to avoid penalties from search engines.

Example usage

[IsPage("home", "/")]
[Route("/", Method.Get)]
[Route("/home", Method.Get)]
[UsesLayout("home")]
internal class HomePage { }

[Route()] attribute properties

The [Route()] attribute has the following properties you can set.

Path

When users navigate to a Url with this path, then this page will be rendered in response. The path should always be absolute, i.e. start with a forward slash.

For dynamic pages the [Route()] attribute can contain wildcards. Wildcards make the page render for a whole set of Urls. In this case the components on the page should contain code to render different content for the various paths that match the wildcard, or the Data Providers referenced by the page elements should put different data into the rendering context based on the path of the Url.

The wildcard character is *. It can be used in place of an element in the path to indicate that anything can appear in this part of the path. For example I can set the Path property to /customer/*/orders to indicate that this page is only rendered if the first element of the path is customer and the third element of the path is orders, but the second element of the path can contain anything. In this case the components and/or data providers for the page should examine the second path element to determine which customer to display orders for.

You can also tell the router to ignore the rest of the path by appending ** to the end of the path. For example if I set the Path property to /customer/order/** then this page will be rendered for any Url that starts with /customer/order/ irrespective of the rest of the path.

Note that you cannot use the * wildcard to match part of a string. This limitation exists for efficiency. Remember that every request is compared to all of the routes until a match is found. Performing complex wildcard matches would make the webisite not scalable.

Methods

This property of the [Route()] attribute defines the Http methods that will be routed to the page. If you do not specify the Methods it will default to new []{ Method.Get }. In this case the page will only be rendered in response to Http GET requests.

You can route all Http methods to the page by setting Methods to an empty array like this: new Method[]{ }

Priority

This property of the [Route()] attribute defines the order in which routing will be evaluated. The highest priority routes are considered before the lower priority ones. Since the default priority is zero, the recommentation is to make very specific routes have positive priorities and wildcard routes have negative priority so that the wildcard routes do not mask the more specific routes by matching the request first.

Priorities also affect performance because the router will try to match routes in order or highest to lowest priority until it finds a match. You can make routing more efficient by giving higher priority to routes that are matched more frequently.