I’m trying to understand ASP.Net MVC at a lower level. Specifically, I’m trying to understand how the MVC runtime gets started. For my initial dig into the call stack / decompilation it appears that it gets started by the MvcRouteHandler which then constructs the MvcHandler. However, I can’t seem to find where the MvcRouteHandler is registered. How does this RouteHandler get added to the ASP.Net pipeline?
Update
Upon further inspection, I have traced the MvcRouteHandler construction into the RouteCollectionExtensions class which looks to contain extensions for the RouteCollection class. The specific method that contains the constructor has the following definition:
public static Route MapRoute(this RouteCollection routes,
string name,
string url,
object defaults,
object constraints,
string[] namespaces)
I believe the key is found in this line of code:
Route route = new Route(url, new MvcRouteHandler());
So, to me this is where the MvcRouteHandler gets assigned. The overall chain of events looks like this:
Everything starts in Global.asax.cs
Application_Start()
RouteConfig.RegisterRoutes
RouteCollectionExtensions.MapRoute(this RouteCollection routes, string name, string url, object defaults)
RouteCollectionExtensions.MapRoute(this RouteCollection routes, string name, string url, object defaults, object constraints)
RouteCollectionExtensions.MapRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces)
From here, it’s just a matter of the route matching, which then causes the MvcRouteHandler to be used which calls into the MvcHandler and starts the entire chains of events. So my initial assumption that the MvcRouteHandler was registered in a config somewhere was wrong. Instead, it is configured via the code starting in the Application_Start event in the global.asax.cs file.
Is this correct?
The request goes through the ASP.net pipeline and then get caught by the
UrlRoutingModuleHTTP module.More info: How does ASP.NET MVC work?
Edit: The routing module is installed in your machine web.config, which your site web.config inherits. You can find it at
%systemroot%\Microsoft.NET\Framework\$versionNumber$\CONFIG\Web.config