Routing in MVC

ASP.MVC routing module is responsible for handling incoming browser request (http request) and map to MVC controller action method.

Routing Module

  • When first time request come to the MVC application, it check for ‘Route Table’ since it is first time request to the application it fills the ‘Route Table‘.
  • Once the ‘Route Table’ is updated then request goes to ‘URL Routing Module’. If the incoming request not first one then it directly goes to ‘URL Routing Module’.
  • And this ‘Routing table’ is created at Application_Start event.

“Default”,                                              // Route name
“{controller}/{action}/{id}”,                           // URL with parameters
new { controller = “Home”, action = “Index”, id = “” }  // Parameter defaults

Name: Default
URL Pattern: {controller}/{action}/{id}
Values: new { controller = “Home”, action = “Index”, id = “” }

  • Depending on the URL sent “UrlRoutingModule” searches the route table to create “RouteData” object which has the details of which controller and action to invoke.
  • From ‘URLRoutingModule’ it goes to ‘MVCHandler’ as RequestContext object, the ‘RouteData’ object is used as RequestContext object.
  • In ‘MVCHandler‘ Controller instance will be created and it calls the ‘Execute‘ method of the controller class.
  • Once ‘ActionMethod‘ executed result will be sent back to view as response object.

Routing module is responsible till it calls the matching ActionMethod.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: