Archive

Posts Tagged ‘Routing in MVC’

Routing in MVC

July 19, 2015 Leave a comment

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.
    “RegisterRoutes(RouteTable.Routes);”

routes.MapRoute(
“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.

Note:-
Routing module is responsible till it calls the matching ActionMethod.

 

Advertisements
Categories: MVC Tags:
%d bloggers like this: