{"id":1154,"date":"2013-10-17T04:00:00","date_gmt":"2013-10-17T04:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2013\/10\/17\/attribute-routing-in-asp-net-mvc-5\/"},"modified":"2013-10-17T04:00:00","modified_gmt":"2013-10-17T04:00:00","slug":"attribute-routing-in-asp-net-mvc-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/attribute-routing-in-asp-net-mvc-5\/","title":{"rendered":"Attribute Routing in ASP.NET MVC 5"},"content":{"rendered":"<p><em>Routing<\/em> is how ASP.NET MVC matches a URI to an action. MVC 5 supports a new type of routing, called <em>attribute routing<\/em>. As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web application.<\/p>\n<p>The earlier style of routing, called convention-based routing, is still fully supported. In fact, you can combine both techniques in the same project.<\/p>\n<p>This post will cover the basic features and options of Attribute Routing, in ASP.NET MVC 5.<\/p>\n<ul>\n<li><a href=\"#why-attribute-routing\">Why Attribute Routing?<\/a><\/li>\n<li><a href=\"#enabling-attribute-routing\">Enabling Attribute Routing<\/a><\/li>\n<li><a href=\"#optionals-and-defaults\">Optional URI Parameters and Default Values<\/a><\/li>\n<li><a href=\"#route-prefixes\">Route Prefixes<\/a><\/li>\n<li><a href=\"#default-route\">Default Route<\/a><\/li>\n<li><a href=\"#route-constraints\">Route Constraints<\/a><\/li>\n<ul>\n<li><a href=\"#custom-route-constraints\">Custom Route Constraints<\/a><\/li>\n<\/ul>\n<li><a href=\"#route-names\">Route Names<\/a><\/li>\n<li><a href=\"#route-areas\">Areas<\/a><\/li>\n<\/ul>\n<h4 id=\"why-attribute-routing\">Why Attribute Routing?<\/h4>\n<p>For example, a socially enhanced e-commerce website could have the following routes:<\/p>\n<ul>\n<li><em><code><em>{productId:int}\/{productTitle}<\/em><\/code><\/em> <br \/>Mapped to <code>ProductsController.Show(int id)<\/code><\/li>\n<li><em><code><em>{username}<\/em><\/code><\/em> <br \/>Mapped to <code>ProfilesController.Show(string username)<\/code><\/li>\n<li><em><code><em>{username}\/catalogs\/{catalogId:int}\/{catalogTitle}<\/em><\/code><\/em> <br \/>Mapped to <code>CatalogsController.Show(string username, int catalogId)<\/code><\/li>\n<\/ul>\n<p>(Don&rsquo;t mind the specific syntax right now, we will touch on this later.)&nbsp;&nbsp;&nbsp;<\/p>\n<p>In previous version of ASP.NET MVC, the rules would be set in the <code>RouteConfig.cs<\/code> file, and point to the actual controller actions, as such:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1a9cd926-d82c-4388-9a5a-f7cb2fef2112\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #000000\">routes.MapRoute(<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">name: <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;ProductPage&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">url: <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{productId}\/{productTitle}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">defaults: <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> { controller = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Products&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, action = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Show&#8221;<\/span><span style=\"background: #ffffff;color: #000000\"> },<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">constraints: <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> { productId = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;\\\\d+&#8221;<\/span><span style=\"background: #ffffff;color: #000000\"> }<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>When the route definitions are co-located with the actions, within the same source file rather than being declared on an external configuration class, it can make it easier to reason about the mapping between URIs and actions. The previous route definition would be set using the following, simple attribute:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f94464e4-4aae-4000-b5b3-a8aa66cf0680\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{productId:int}\/{productTitle}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Show(<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\"> productId) { &#8230; }<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<h4 id=\"enabling-attribute-routing\">Enabling Attribute Routing<\/h4>\n<p>To enable attribute routing, call <code>MapMvcAttributeRoutes<\/code> during configuration.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b8bb4f10-5dce-4230-a0ba-b5a53d484936\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">RouteConfig<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">static&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> RegisterRoutes(RouteCollection routes)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.IgnoreRoute(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{resource}.axd\/{*pathInfo}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.MapMvcAttributeRoutes();<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>You can also combine attribute routing with convention-based routing.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5eda09bc-0367-4d87-a72f-b02f98cb9b3d\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">static&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> RegisterRoutes(RouteCollection routes)<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.IgnoreRoute(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{resource}.axd\/{*pathInfo}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.MapMvcAttributeRoutes();<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.MapRoute(<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">name: <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Default&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">url: <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{controller}\/{action}\/{id}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">defaults: <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> { controller = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Home&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, action = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Index&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, id = <\/span><span style=\"background: #ffffff;color: #2b91af\">UrlParameter<\/span><span style=\"background: #ffffff;color: #000000\">.Optional }<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<h4 id=\"optionals-and-defaults\">Optional URI Parameters and Default Values<\/h4>\n<p>You can make a URI parameter optional by adding a question mark to the route parameter. You can also specify a default value by using the form parameter=value.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e0314629-40d4-4844-b898-7a48a5db63cb\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">BooksController<\/span><span style=\"background: #ffffff;color: #000000\"> : <\/span><span style=\"background: #ffffff;color: #2b91af\">Controller<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/books<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/books\/1430210079<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;books\/{isbn?}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> View(<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> isbn)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">if<\/span><span style=\"background: #ffffff;color: #000000\"> (!<\/span><span style=\"background: #ffffff;color: #2b91af\">String<\/span><span style=\"background: #ffffff;color: #000000\">.IsNullOrEmpty(isbn))<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> View(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;OneBook&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, GetBook(isbn));<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> View(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;AllBooks&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, GetBooks());<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/books\/lang<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/books\/lang\/en<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/books\/lang\/he<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;books\/lang\/{lang=en}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> ViewByLanguage(<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> lang)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> View(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;OneBook&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, GetBooksByLanguage(lang));<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>In this example, both <code>\/books<\/code> and <code>\/books\/1430210079<\/code> will route to the &ldquo;View&rdquo; action, the former will result with listing all books, and the latter will list the specific book. Both <code>\/books\/lang<\/code> and <code>\/books\/lang\/en<\/code> will be treated the same.<\/p>\n<h4 id=\"route-prefixes\">Route Prefixes<\/h4>\n<p>Often, the routes in a controller all start with the same prefix. For example:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:55ab500c-26e5-427a-b021-4a2728c49cdf\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ReviewsController<\/span><span style=\"background: #ffffff;color: #000000\"> : <\/span><span style=\"background: #ffffff;color: #2b91af\">Controller<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/reviews<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;reviews&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Index() { &#8230; }<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/reviews\/5<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;reviews\/{reviewId}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Show(<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\"> reviewId) { &#8230; }<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/reviews\/5\/edit<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;reviews\/{reviewId}\/edit&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Edit(<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\"> reviewId) { &#8230; } <\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>You can set a common prefix for an entire controller by using the <code>[RoutePrefix]<\/code> attribute:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1eca4971-7783-4fd9-91b8-8820fdf94089\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">RoutePrefix<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;reviews&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ReviewsController<\/span><span style=\"background: #ffffff;color: #000000\"> : <\/span><span style=\"background: #ffffff;color: #2b91af\">Controller<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{ <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg.: \/reviews <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">] <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Index() { &#8230; } <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg.: \/reviews\/5 <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{reviewId}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Show(<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\"> reviewId) { &#8230; } <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg.: \/reviews\/5\/edit <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{reviewId}\/edit&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Edit(<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\"> reviewId) { &#8230; } <\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>Use a tilde (~) on the method attribute to override the route prefix if needed:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:729ce49f-03e6-43af-9267-c8ab0e762dd4\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">RoutePrefix<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;reviews&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ReviewsController<\/span><span style=\"background: #ffffff;color: #000000\"> : <\/span><span style=\"background: #ffffff;color: #2b91af\">Controller<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{ <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg.: \/spotlight-review <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;~\/spotlight-review&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> ShowSpotlight() { &#8230; } <\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">&#8230;<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<h4 id=\"default-route\">Default Route<\/h4>\n<p>You can also apply the [Route] attribute on the controller level, capturing the action as a parameter. That route would then be applied on all actions in the controller, unless a specific [Route] has been defined on a specific action, overriding the default set on the controller.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:48e76016-8e2d-4177-83f0-8f7c7c5cf96e\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">RoutePrefix<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;promotions&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{action=index}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ReviewsController<\/span><span style=\"background: #ffffff;color: #000000\"> : <\/span><span style=\"background: #ffffff;color: #2b91af\">Controller<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{ <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg.: \/promotions <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Index() { &#8230; } <\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg.: \/promotions\/archive <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Archive() { &#8230; } <\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg.: \/promotions\/new <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult&nbsp;<\/span><span style=\"background-color: #ffffff;color: #000000\">New<\/span><span style=\"background: #ffffff;color: #000000\">() { &#8230; } <\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg.: \/promotions\/edit\/5 <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;edit\/{promoId:int}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)] <\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Edit(<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\"> promoId) { &#8230; } <\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<h4 id=\"route-constraints\">Route Constraints<\/h4>\n<p>Route constraints let you restrict how the parameters in the route template are matched. The general syntax is <code>{parameter:constraint}<\/code>. For example:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3e725652-6935-42a9-9340-3a6a8269bf06\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/users\/5<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;users\/{id:int}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"><span style=\"color: #2b91af\"> ActionResult<\/span> GetUserById(<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\"> id) { &#8230; }<\/span><\/li>\n<li>&nbsp;<\/li>\n<li><span style=\"background: #ffffff;color: #008000\">\/\/ eg: users\/ken<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;users\/{name}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"><span style=\"color: #2b91af\"> ActionResult<\/span> GetUserByName(<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> name) { &#8230; }<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>Here, the first route will only be selected if the &#8220;id&#8221; segment of the URI is an integer. Otherwise, the second route will be chosen.<\/p>\n<p>The following table lists the constraints that are supported.<\/p>\n<p>&nbsp;<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\">\n<thead>\n<tr>\n<th>Constraint<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>alpha<\/td>\n<td>Matches uppercase or lowercase Latin alphabet characters (a-z, A-Z)<\/td>\n<td>{x:alpha}<\/td>\n<\/tr>\n<tr>\n<td>bool<\/td>\n<td>Matches a Boolean value.<\/td>\n<td>{x:bool}<\/td>\n<\/tr>\n<tr>\n<td>datetime<\/td>\n<td>Matches a <strong>DateTime<\/strong> value.<\/td>\n<td>{x:datetime}<\/td>\n<\/tr>\n<tr>\n<td>decimal<\/td>\n<td>Matches a decimal value.<\/td>\n<td>{x:decimal}<\/td>\n<\/tr>\n<tr>\n<td>double<\/td>\n<td>Matches a 64-bit floating-point value.<\/td>\n<td>{x:double}<\/td>\n<\/tr>\n<tr>\n<td>float<\/td>\n<td>Matches a 32-bit floating-point value.<\/td>\n<td>{x:float}<\/td>\n<\/tr>\n<tr>\n<td>guid<\/td>\n<td>Matches a GUID value.<\/td>\n<td>{x:guid}<\/td>\n<\/tr>\n<tr>\n<td>int<\/td>\n<td>Matches a 32-bit integer value.<\/td>\n<td>{x:int}<\/td>\n<\/tr>\n<tr>\n<td>length<\/td>\n<td>Matches a string with the specified length or within a specified range of lengths.<\/td>\n<td>{x:length(6)} <br \/>{x:length(1,20)}<\/td>\n<\/tr>\n<tr>\n<td>long<\/td>\n<td>Matches a 64-bit integer value.<\/td>\n<td>{x:long}<\/td>\n<\/tr>\n<tr>\n<td>max<\/td>\n<td>Matches an integer with a maximum value.<\/td>\n<td>{x:max(10)}<\/td>\n<\/tr>\n<tr>\n<td>maxlength<\/td>\n<td>Matches a string with a maximum length.<\/td>\n<td>{x:maxlength(10)}<\/td>\n<\/tr>\n<tr>\n<td>min<\/td>\n<td>Matches an integer with a minimum value.<\/td>\n<td>{x:min(10)}<\/td>\n<\/tr>\n<tr>\n<td>minlength<\/td>\n<td>Matches a string with a minimum length.<\/td>\n<td>{x:minlength(10)}<\/td>\n<\/tr>\n<tr>\n<td>range<\/td>\n<td>Matches an integer within a range of values.<\/td>\n<td>{x:range(10,50)}<\/td>\n<\/tr>\n<tr>\n<td>regex<\/td>\n<td>Matches a regular expression.<\/td>\n<td>{x:regex(^\\d{3}-\\d{3}-\\d{4}$)}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Notice that some of the constraints, such as &#8220;min&#8221;, take arguments in parentheses.<\/p>\n<p>You can apply multiple constraints to a parameter, separated by a colon, for example:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6cd484ae-7f95-4431-86e7-5f26c5ba6515\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #008000\"><span>\/\/ eg: \/users\/5<br \/>\/\/ but not \/users\/10000000000 because it is larger than int.MaxValue,<br \/>\/\/ and not \/users\/0 because of the min(1) constraint.<\/span><\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;users\/{id:int:min(1)}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"><span style=\"color: #2b91af\"> ActionResult<\/span> GetUserById(<\/span><span style=\"background: #ffffff;color: #0000ff\">int<\/span><span style=\"background: #ffffff;color: #000000\"> id) { &#8230; }<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Specifying that a parameter is Optional (via the &#8216;?&#8217; modifier) should be done after inline constraints:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6cd484ae-7f95-4431-86e7-5f26c5ba6515\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<p>&nbsp;<\/p>\n<div style=\"border: 1px solid #000080;color: #000000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #dddddd;overflow: auto;max-height: 300px\">\n<ul style=\"background: #ffffff;margin: 0px;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #008000\"><span><span style=\"background: #ffffff;color: #008000\"><span>\/\/ eg: \/greetings\/bye<br \/><\/span><\/span><\/span><\/span><span style=\"background: #ffffff;color: #000000\"><span style=\"background: #ffffff;color: #008000\"><span><span style=\"background: #ffffff;color: #008000\"><span>\/\/ and&nbsp;\/greetings because of the Optional modifier,<br \/><\/span><\/span>\/\/ but not&nbsp;\/greetings\/see-you-tomorrow because of the maxlength(3) constraint.<br \/><\/span><\/span>[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;greetings\/{message:maxlength(3)?}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"><span style=\"color: #2b91af\"> ActionResult<\/span> Greet(<span style=\"background: #ffffff;color: #0000ff\">string <\/span>message<\/span><span style=\"background: #ffffff;color: #000000\">) { &#8230; }<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<h5 id=\"custom-route-constraints\">Custom Route Constraints<\/h5>\n<p>You can create custom route constraints by implementing the <code>IRouteConstraint<\/code> interface. For example, the following constraint restricts a parameter to set of valid values:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c99baa2e-5897-45ee-96fd-c3d0197f94ea\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ValuesConstraint<\/span><span style=\"background: #ffffff;color: #000000\"> : <\/span><span style=\"background: #ffffff;color: #2b91af\">IRouteConstraint<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">private&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">readonly&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\">[] validOptions;<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"> ValuesConstraint(<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> options)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">validOptions = options.Split(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8216;|&#8217;<\/span><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">bool<\/span><span style=\"background: #ffffff;color: #000000\"> Match(<\/span><span style=\"background: #ffffff;color: #2b91af\">HttpContextBase<\/span><span style=\"background: #ffffff;color: #000000\"> httpContext, <\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\"> route, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> parameterName, <\/span><span style=\"background: #ffffff;color: #2b91af\">RouteValueDictionary<\/span><span style=\"background: #ffffff;color: #000000\"> values, <\/span><span style=\"background: #ffffff;color: #2b91af\">RouteDirection<\/span><span style=\"background: #ffffff;color: #000000\"> routeDirection)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">object<\/span><span style=\"background: #ffffff;color: #000000\"> value;<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">if<\/span><span style=\"background: #ffffff;color: #000000\"> (values.TryGetValue(parameterName, <\/span><span style=\"background: #ffffff;color: #0000ff\">out<\/span><span style=\"background: #ffffff;color: #000000\"> value) &amp;&amp; value != <\/span><span style=\"background: #ffffff;color: #0000ff\">null<\/span><span style=\"background: #ffffff;color: #000000\">)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> validOptions.Contains(value.ToString(), <\/span><span style=\"background: #ffffff;color: #2b91af\">StringComparer<\/span><span style=\"background: #ffffff;color: #000000\">.OrdinalIgnoreCase);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">false<\/span><span style=\"background: #ffffff;color: #000000\">;<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>The following code shows how to register the constraint:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:58cf9782-1323-4e37-8709-003f7e0109e4\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">RouteConfig<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">static&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> RegisterRoutes(<\/span><span style=\"background: #ffffff;color: #2b91af\">RouteCollection<\/span><span style=\"background: #ffffff;color: #000000\"> routes)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.IgnoreRoute(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{resource}.axd\/{*pathInfo}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">var<\/span><span style=\"background: #ffffff;color: #000000\"> constraintsResolver = <\/span><span style=\"background: #ffffff;color: #0000ff\">new&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">DefaultInlineConstraintResolver<\/span><span style=\"background: #ffffff;color: #000000\">();<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">constraintsResolver.ConstraintMap.Add(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;values&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #0000ff\">typeof<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #2b91af\">ValuesConstraint<\/span><span style=\"background: #ffffff;color: #000000\">));<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.MapMvcAttributeRoutes(constraintsResolver);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>Now you can apply the constraint in your routes:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7e660002-1ef0-4d5b-8b63-74091bc3dc6e\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">TemperatureController<\/span><span style=\"background: #ffffff;color: #000000\"> : <\/span><span style=\"background: #ffffff;color: #2b91af\">Controller<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: temp\/celsius and \/temp\/fahrenheit but not \/temp\/kelvin<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;temp\/{scale:values(celsius|fahrenheit)}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Show(<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> scale)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> Content(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;scale is &#8220;<\/span><span style=\"background: #ffffff;color: #000000\"> + scale);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<h4 id=\"route-names\">Route Names<\/h4>\n<p>You can specify a name for a route, in order to easily allow URI generation for it. For example, for the following route:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:60c6c3c5-5ed0-4ba6-9804-f8961bc38784\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;menu&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, Name = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;mainmenu&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> MainMenu() { &#8230; }<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>you could generate a link using <code>Url.RouteUrl<\/code>:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fcbe4da8-6a43-42c2-a85c-85c43a66feca\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #0000ff\">&lt;<\/span><span style=\"background: #ffffff;color: #800000\">a&nbsp;<\/span><span style=\"background: #ffffff;color: #ff0000\">href<\/span><span style=\"background: #ffffff;color: #0000ff\">=&#8221;<\/span><span style=\"background: #ffff00;color: #000000\">@<\/span><span style=\"background: #ffffff;color: #000000\">Url.RouteUrl(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;mainmenu&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)<\/span><span style=\"background: #ffffff;color: #0000ff\">&#8220;&gt;<\/span><span style=\"background: #ffffff;color: #000000\">Main menu<\/span><span style=\"background: #ffffff;color: #0000ff\">&lt;\/<\/span><span style=\"background: #ffffff;color: #800000\">a<\/span><span style=\"background: #ffffff;color: #0000ff\">&gt;<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<h4 id=\"route-areas\">Areas<\/h4>\n<p>You can define that a controller belongs to an area by using the <code>[RouteArea]<\/code> attribute. When doing so, you can safely remove the AreaRegistration class for that area.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fa602c1b-21ff-46c9-976e-bb96888456ce\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">RouteArea<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Admin&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">RoutePrefix<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;menu&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{action}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">class&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">MenuController<\/span><span style=\"background: #ffffff;color: #000000\"> : <\/span><span style=\"background: #ffffff;color: #2b91af\">Controller<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/admin\/menu\/login<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Login() { &#8230; }<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/admin\/menu\/show-options<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;show-options&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Options() { &#8230; }<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ eg: \/stats<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">Route<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;~\/stats&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">)]<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\"> Stats() { &#8230; }<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>With this controller, the following link generation call will result with the string &#8220;<em>\/Admin\/menu\/show-options<\/em>&#8220;<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:62bc1c20-a7ba-4d11-b51d-6e6e452365d0\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #000000\">Url.Action(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Options&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Menu&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> { Area = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Admin&#8221;<\/span><span style=\"background: #ffffff;color: #000000\"> })<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>You can set up a custom prefix for the area that defer from the area name, by using the <code>AreaPrefix<\/code>&nbsp;named parameter, for example:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fa602c1b-21ff-46c9-976e-bb96888456ce\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">RouteArea<\/span><span style=\"background: #ffffff;color: #000000\">(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;BackOffice&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, AreaPrefix = <span style=\"background: #ffffff;color: #a31515\">&#8220;back-office&#8221;<\/span>)]<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>If you are using both Areas with route attributes, and areas with convention based routes (set by an <code>AreaRegistration<\/code> class), then you need to make sure that area registration happen after MVC attribute routes are configured, however before the default convention-based route is set. The reason is that route registration should be ordered from the most specific (attributes) through more general (area registration) to the mist generic (the default route) to avoid generic routes from &ldquo;hiding&rdquo; more specific routes by matching incoming requests too early in the pipeline.<\/p>\n<p>Example:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3cf1250f-e6c7-4e3b-bf5b-27693fdc2660\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ul style=\"background: #ffffff;margin: 0;padding: 0.5em 1.5em;list-style-type: none\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">static&nbsp;<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> RegisterRoutes(RouteCollection routes)<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.IgnoreRoute(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{resource}.axd\/{*pathInfo}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.MapMvcAttributeRoutes();<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #2b91af\">AreaRegistration<\/span><span style=\"background: #ffffff;color: #000000\">.RegisterAllAreas();<\/span><\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">routes.MapRoute(<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">name: <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Default&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">url: <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;{controller}\/{action}\/{id}&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">defaults: <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> { controller = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Home&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, action = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;Index&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, id = <\/span><span style=\"background: #ffffff;color: #2b91af\">UrlParameter<\/span><span style=\"background: #ffffff;color: #000000\">.Optional }<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Routing is how ASP.NET MVC matches a URI to an action. MVC 5 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web application. The earlier style of routing, called convention-based routing, is [&hellip;]<\/p>\n","protected":false},"author":436,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[7333,7286],"class_list":["post-1154","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-asp-net-mvc","tag-mvc"],"acf":[],"blog_post_summary":"<p>Routing is how ASP.NET MVC matches a URI to an action. MVC 5 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web application. The earlier style of routing, called convention-based routing, is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/1154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/436"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=1154"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/1154\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=1154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=1154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=1154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}