AmazonBanner

MVC Life Cycle / Request Execution Steps

In  ASP.NET MVC unlike ASP.NET Web Forms we do not have page life cycle events. In ASP.NET MVC It is referred as Request execution steps / Cycle.
For better understanding we would divide whole request execution in request and response cycle.
The Starting point of request response cycle is HttpRequest server receives HttpRequest which then passed on to IIS Pipeline. IIS Pipeline then pass this request to URL Routing Module (System.Web.Routing).

URL Routing Module inspects incoming request with matching file on disk. If any matching file is found URL Routing Module will pass the request back to IIS to serve that file. If incoming request does not match with any incoming request Routing Module will check for any matching route in routing table. If no matching route is found in Routing table, Routing Module will throw 404 (Not Found Error).


If URL Routing Module finds any matching route with the request it creates an object of Route Handler which invokes an object of HTTPHandler to server this request.


Response :-

MVC HTTPHandler initialise and executes Controller with help of Controller Factory and Controller Activator. HttpHandler locates correct Controller with the help of Controller Factory then initialise it with help of Controller Activator. Controller Activator checks for any Dependency Injection while initialising controller and resolves it, if found. Post Dependency resolution ActionInvoker invokes appropriate action with help of RouteData. Prior ActionInvoker invokes action from Controller, it executes all Action Filters and performs ModelBinding.


Post executing business logic from action methods. It comes to rendering a view. To render a view ActionInvoker calls method ExecutesResult on ViewResultBase class. This method finds view and invokes Render method from IView. This method actually creates / writes HTML output to response.

This post is just to provide over view of ASP.NET MVC Life Cycle or Request Execution process. We would deep dive in each segment of Request response cycle to have more details.

Comments

Popular Posts