Click here to Skip to main content
12,888,931 members (50,582 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 11 Apr 2014

What is ASP.NET MVC Routing and Why Is It Needed, Explained.

, 11 Apr 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
What is ASP.NET MVC Routing and why is it needed


The ASP.NET Routing Framework is at the core of every ASP.NET MVC request and it is simply a pattern-matching system. At the application start-up, it registers one or more patterns with route table of the framework to tell it what to do with the pattern matching requests. For routing, the main purpose is to map URLs to a particular action in a specific controller.

When the routing engine receives any request, it first matches the request URL with the patterns already registered with it. If it finds any matching pattern in route table, it forwards the request to the appropriate handler for the request. If the request URL does not match with any of the registered route patterns, the routing engine returns a 404 HTTP status code.

Where to Configure

  • Global asax

How to Configure

ASP.NET MVC routes are responsible for determining which controller methods need to be executed for the requested URL. The properties for this to be configured are:

  • Unique Name: A name unique to a specific route
  • URL Pattern: A simple URL pattern syntax
  • Defaults: An optional set of default values for each segment defined in URL pattern
  • Constraints: A set of constraints to more narrowing the URL pattern to match more exactly

The RegisterRoute method in RouteConfig.cs file is as follows:

public class RouteConfig
public static void RegisterRoutes(RouteCollection routes)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // ignore route with extension .axd

 name: "Default", // Name of the route
url: "{controller}/{action}/{id}", // pattern for the url
 defaults: new { controller = "Login", action = "Index", 
     id = UrlParameter.Optional } // default values for each section

Then in Global.asax.cs file, call this on application start event handler so that this will be registered on application start itself:

protected void Application_Start()

How Routing Engine Works

Route Matching

Hope this will give a clear understanding on what is routing and how routing engine works...



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

SRS(The Coder)
Software Developer
India India
Having more than 6 years of development experience in various Microsoft Technologies like :-
ASP.Net, MVC, SQL Server, WCF, MS Commerce Server, Xamarin etc.

Also hands on experience on the client side coding with JavaScript/jQuery and framework like AngularJS.Worked with third party controls like Telerik and DevExpress as well.

Very much interested in Microsoft technologies to explore and implement. Now started to helping coders who really need me.

My Blog

Microsoft Technology Master

Programming Communities

JS Fiddle | Stack Overflow


Microsoft MCTS Certification in ASP.Net 4.0

You may also be interested in...


Comments and Discussions

GeneralShort article Pin
Gaurav.Kumar.Arora27-Oct-14 11:38
memberGaurav.Kumar.Arora27-Oct-14 11:38 
GeneralMy vote of 2 Pin
Gaurav.Kumar.Arora27-Oct-14 11:37
memberGaurav.Kumar.Arora27-Oct-14 11:37 
GeneralMy vote of 2 Pin
Andrew Brown31-Jul-14 4:04
memberAndrew Brown31-Jul-14 4:04 
GeneralMy vote of 1 Pin
Mahmoud Habib15-Apr-14 21:30
memberMahmoud Habib15-Apr-14 21:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 11 Apr 2014
Article Copyright 2014 by SRS(The Coder)
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid