ASP.NET MVC Default Route

Sponsored Links

ASP.NET MVC Default Route

Here we look at the ASP.NET MVC Default Route, that is the URL Route.

Url Routing

ASP.NET MVC uses the .NET Routing classes as default to control how URLs appear for a website. The routing engine makes the URLs appear more user friendly, (and also more SEO friendly), by producing a URL which is a little bit more structured and easy to read than a basic average URL. For starters the file type extension is removed from the end, and forward slashes ('/') are used not just for indicating a subfolder, but can be used to split the URL into variables which indicate what to expect from the URL.

For instance, on this website there is a page with a link - Now if this link was produced with the .NET Routing engine, it may look more like

The routing can be quite flexible and you can configure it to match specific URL patterns, depending on the structural design of your website. When you create a new website in Visual Studio 2010 with MVC 2, you get a default URL pattern to begin with. These patterns can be found in the Global.asax.cs file.

ASP.NET MVC Default Route

Without explaining here the Routing syntax, the default route specified for MVC is:



This is looking for a pattern in the URL which matches this, so http://.....a/b/c would match this pattern.

The URL - would match this pattern.

asp-mvc/page/1 - This is the part which matches the pattern, {controller}/{action}/{id}. So 'asp-mvc' would be the Controller, 'page' would be the Action, and '1' would be the Id (or almost querystring parameter one could say). So this URL would call the asp-mvc Controller, which would be called asp-mvcController, and it's Action method called 'Page' would be invoked, and the Id, '1' would be passed as a value to the action method.