ASP.NET MVC Default Route


InterServer Web Hosting and VPS
Sony Playstation PS4 Pro Custom Build NVMe SSD Drive - Enclosure case and Crucial NVMe SSD
PS4 Pro Custom External SSD NVMe Drive

How I built a PS4 Pro Custom External SSD NVMe Drive...

NUC8i7BEH with memory
Intel NUC8I7BEH Review and Custom Build

This is my review of the Intel NUC8i7BEH and a summary of my build...

Card image cap
Asus M5A88-M EVO Review

This is my review of the Asus M5A88-M EVO motherboard...

Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit
Corsair Vengeance Blue Review

This is my review of the Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit memory...

Robotic Arm with USB PC Interface Review
Robotic Arm with USB PC Interface Review

This is my review of the Robotic Arm with USB PC Interface...

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 - http://www.high-flying.co.uk/asp-mvc/What-Is-ASP-MVC.html. Now if this link was produced with the .NET Routing engine, it may look more like http://www.high-flying.co.uk/asp-mvc/What-Is-ASP-MVC

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:


    "{controller}/{action}/{id}"

Controller/Action/Id

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

The URL - http://www.high-flying.co.uk/asp-mvc/page/1 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.

Sponsored Links
SolarSystem - AngularJS Demo
SolarSystem - Angular JS Demo

Check out my first Angular JS demo hosted in Azure, it helped win my first Angular contract. Put the sound on.