Wednesday, 21 January 2015

MVC Request Life Cycle

Asp.Net MVC life cycle steps are as follows

1.Routing
2.MVCHandler
3.Controller
4.Action Execution
5.ViewResult
6.View Engine
7.View


Routing: Request go to the  Global.asax file of the application

protected void Application_Start()
        {
                       RouteConfig.RegisterRoutes(RouteTable.Routes);
        }


Its check whether that request is present in the RouteTable or not.
If present call the routing in RouteConfig.cs under App_Start folder.

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );


MVCHandler:  It initiate the real process,find the proper controller and calls it.

Controller: Once  Controller found it looks requested action method in it.

Action Execution: Then do execution of that Action method.(Action Result is super class for all action methods).

View Result: Once it get executed return the result, There are different ways(action result,json result,file result etc).

View Engine: Now we have result of our action method we need to display that on view,for that we need mediator to transfer.So we use view engines for that(ASPX or Razor).

View: This is our final destination for the end user to display result.

No comments:

Post a Comment