Understanding ASP.NET MVC request process.

There is a greate visual representaion of a request pipeline process decribed in Steven Sanderson’s MVC Pipleline Poster.

asp_net__mvc_request_pipeline_poster

 

Routing.

The incomming HTTP request comes to IIS and then is picked up by UrlRoutingModule(System.Web.Routing). If no files were serverd on disk directly module parses incoming URLs according to your configured routing schema(RouteTable.Routes), and then dispatches control to the matching route handler, typically controller. If no routes match, the UrlRoutingModule object does nothing and lets the request fall back to the regular ASP.NET or IIS request processing. Routing lets you define an arbitrary clean, human-readable, searchengine optimized (SEO) URL structure independently of the code that handles those URLs. UrlRoutingModule creates RoutData object, which it then uses to create RequestContext object.

Controllers and Actions.

MvcRouteHandler object create an instance of the MvcHandler class and passes RequestContenxt instance to the handler. Then, MvcHandler uses the RequestContenxt object to identify IControllerFactory object(typically, an instance of the DefaultControllerFactory class) to create the controller instance with. The MvcHandler calls the created controller’s Execute method. For controllers that inherit from the ControllerBaseclass, the ControllerActionInvoker object that is associated with the controller determines which action method of the controller class to call, and then calls that method. Before and after action method is invoked ASP.NET MVC filters could be applied. More information about this you can fnd in my blog post Filters in ASP.NET MVC.

Views.

The action method receives user input, prepares the appropriate response data, and then executes the result by returning a result type. ViewResult type(in most of the cases) i.e. view and partial view are represented by IView(System.Web.Mvc.IView) interface and rendered by the appropriate View Engine. This process is handled by IViewEngine(System.Web.Mvc.IViewEngine) interface of the view engine. By default ASP.NET MVC provides WebForm and Razor view engines. You can also create your custom engine by using IViewEngine interface and can registered your custom view engine in to your Asp.Net MVC application.
Note:The built-in result types that can be executed include the following: ViewResult (which renders a view and is the most-often used result type), RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, FileResult, and EmptyResult.

Share this post:Tweet about this on TwitterShare on Facebook0Share on LinkedIn0Share on Google+0Share on Reddit0Email this to someoneDigg this