Friday, March 1, 2013

[ASP .Net MVC3] ASP.Net MVC Execution flow

Ref

A typical flow of Web Request comes to MVC Application is handled as follows

WebRequest ->  UrlRoutingModule -> MVCRouteHandler (Extracted from Route Object and implements IRouteHandler) 
  1. MvcHandler (IHttpHandler) 
  2. RequestContext
-> Controller

So to understand it better let see the flow simpler way :-

At very first request comes to UrlRoutingModule which is a http module very similar to the any web request processor (Asp.Net engine or IIS). This parse the request and select route from requested URL. Once parsing complete UrlRoutingModule select the first route object which matches to the parsed request. (Route object is the object which is used at Global.asax). read more about routing object

if no route is matched url is processed as normal url (as processed on asp.net or iis).


After route object is selected RequestContext is created and an instance of MvcRouteHandler is extract from the route object creates MvcHanlder object and pass RequestContext to it.

Once MvcHandler object is obtained, MVCHandler selects appropriate Controller to serve request.

Later Execute method is performed on the controller to perform the action.

For controllers that inherit from the ControllerBase class, the ControllerActionInvoker object that is associated with the controller determines which action method of the controller class to call, and then calls that method.

Once Action is executed Result is served as Allowed Result Type (i.e. ViewResult, RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, FileResult, and EmptyResult.)


No comments:

Post a Comment