Today, I will try to explain ASP.NET MVC Routing from prespective of a Webforms developer. Attempt over here is to stay away from page lifecycle and be focused till the instantiation of the page/controller class.

ASP.NET Web Forms

As such there is no routing in ASP.NET Webforms. But if you look at a page class, often you would have a question how is the page class instantiated. Class responsible for creating a page object is PageHandlerFactory. This class is registerd in web.config and in simple words the request pipeline is like.

  1. Execute modules registered in web.config
  2. Get the Page object using the PageHandlerFactory regiestered in web.confg. PageHandlerFactory’s GetHandler returns an Object that implements IHttpHandler, in case of .aspx request it is Page class that implements the IHttpHandler interface. But the actual instance returned is not the codebehind class but a class derived from code behind class (Details)
  3. Invoke the ProcessRequest method of the Handler returned by the PageHandlerFactory. After this step the page events are invoked.


Now, what happens in case of MVC is that Page (which is an IHttpHandler ) is replaced by another class that implements IHttpHandler that is MvcHandler, and the class responsible for creation of MvcHandler is MvcRouteHandler (method GetHttpHandler) which is equivalent of PageHandlerFactory (GetHandler).

But the question is what stage is it determined to use MVC objects but not the Webform ones. This is done by a module called UrlRoutingModule, UrlRoutingModule attaches itself to PostResolveRequestCache and PostMapRequestHandler events of the HttpApplication instance and overrides the default behaviour of MapRequestHandler stage.

At this stage the Route Table to which routes are set in Application Startup (as following) is used to determine if the URL match to one of the routes defined, by default it uses MvcRouteHandler, which can be overwritten by custom routehandler.

public class MvcApplication: System.Web.HttpApplication {
 public static void RegisterRoutes(RouteCollection routes) {

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


 protected void Application_Start() {

So, in simple words UrlRoutingModule returns MvcRouteHandler which returns MvcHandler, now MvcHandler is the class that create an instance of the controller using controller factory.