A day with .Net

My day to day experince in .net

ASP.NET MVC Request Pipeline and participating classes – Familiarization – Part1 – Routing

Posted by vivekcek on May 28, 2013

In this post, i would like to give you a small overview how MVC is working. I advise you to have a better look at System.Web.Routing and System.Web.Mvc. You can download MVC source code from codeplex too.

1. Request like http://mysite.com/Home/Index is issued by the browser.

The routing mechanism in MVC is implemented by System.Web.Routing available with .NET 4.0.
When the Application_Start() in Global.asax is fired, we register all Routes in our application and which will be stored in RouteTable.

Have a look at the high level diagram of classes in System.Web.Routing.

1

Now have a look at a detailed diagram of classes in System.Web.Routing.

2

UrlRoutingModule(System.Web.Routing)
—————————————————–

UrlRoutingModule is an HttpModule. Which inspect our URL pattern {controller}/{action} and try to match that pattern against Routes in RouteCollection.

Once a match is found, UrlRoutingModule call the GetHttpHandler() method of Route.
(GetHttpHandler() method is defined in IRouteHandler interface. Route class implement this interface)

At the same time UrlRoutingModule create RouteData and wrap it in a RequestContext object.

RouteData contain your request parameters.

ex: var controller=RouteData.Values[“Controller”];

So back to GetHttpHandler() method , which will return an instance of UrlRoutingHandler.
UrlRoutingModule pass the RequestContext to UrlRoutingHandler’s ProcessRequest() method.

3


UrlRoutingHandler(System.Web.Routing)

———————————————

UrlRoutingHandler create an instance of MvcHandler(System.Web.Mvc) and pass the RequestContext. From here we enter to the MVC Request Pipeline. That will be explained in next post

4

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s