ASP.NET MVC - Life Cycle

I bet you that it will be very easy for you to understand the MVC Application Life Cycle in my article.Come, let us dive into ASP.NET MVC APPLICATION LIFE CYCLE. In simple terms, user request url in browser and goes through some sequence of steps and response is returned to User. The asp.net mvc life cycle consists of the following blocks such as,

  • Request
  • Routing
  • MVCHandleer
  • Controller
  • Action Execution
  • View Result
  • View Engine
  • View
  • Response

Please Visit ASP.NET MVC PAGE LIFE CYCLE to understand it more clearly
When asp.net MVC application starts first time.It registers one or more patterns to the Route Table. The application has one route table at application_start() in Global.asax file.
Request
The user enters the Url request in the browser.
Routing
When browser request any url, it checks whether this request is matching with the request that is present in the RouteTable. If it matches then it forwards to the MVCHandler.
MVC Handler
It is responsible for processing the request and implements ihttphandler.
Controller
MVC Handler uses icontrollerfactory and creates instance for the controller.Once it is success, it calls the execute method.
Action Execution
Here action invoker determines which action to be executed on controller.Action to be executed based on ActionSelectorAttribute such as ActionName,ActionVerbs or NonAction

[ActionName("find")]
public ActionResult GetById(int id)
{
return view();
}
            

so now action name is "find" instead of "GetById".This action must be invoked on the browser like http://localhost/student/find/1 and internally it calls GetById().
ViewResult
Here it executes the result and return the result type in either viewresult or jsonresult or redirectresult.

                
public ActionResult Index()
{
//returning the viewresult here
return view();
}
            

ViewEngine
In order to execute viewresult it needs to select correct view engine,which is either RAZOR engine or ASPX engine.
View
The actionresult is viewresult and returns the result as HTML to view using ViewEngine.

                
public ActionResult Index()
{
//returning the viewresult here
return view();
}
            

Response
So final output will be rendered in the browser as HTML response like this page.