Hello Friends, In this tutorial, I am going to explain you ASP.NET MVC Page Life Cycle. While learning ASP.NET MVC it is important to know about Life Cycle of application from start to end. This is also mostly asked Interview Questions.  Let’s start the tutorial.

After completing this tutorial you will be able to understand:

  • RouteTable in ASP.NET MVC Routing.
  • ASP.NET MVC Page Life Cycle.

Introduction to ASP.NET MVC Page Life Cycle:

Before come to the main topic let’s  understand core concept about route table in Routing.

In ASP.NET there is always a one-to-one relationship between the URLS and the pages means there is always one URL for one page. But in the case of ASP.NET MVC, there is a many-to-one relationship between URL and pages. i.e. multiple URL can be mapped to one controller. For example.

  1. http://mydomain/Employee/1
  2. http://mydomain/Employee/2
  3. http://mydomain/Employee/3

The ASP.NET has RouteTable to map the particular controller to particular URL. A project can have only one Route Table. The Route Table is initiated in the Global.asax.

Life Cycle

The following are the Life Cycle of ASP.NET MVC:

Step 1- Register Route Table.

When an ASP.NET MVC application starts at the first time the first thing that happens is to fill the route table. The Routing System decides what to do if any matching pattern found in the Route Table. So in this step, the incoming URL is mapped to the registered URL.

Step 2- Retrieve  Route.

If any matching URL is found the URLRoutingModule created the RouteData. This RouteData Contains the information for Controller and Action.

Step 3- Create RouteContext:

If URLRoutingModule successfully retrieves the RouteData the next step is to create RouteContext Object. This RouteContext object represents the current HTTPContext and RouteData.

Step 4- Create Controller Instance.

After the successful creation of a RouteContext object that comes in front is to create the instance of the Controller. This Requested object is sent to MVCHandler to create an instance of the Controller class. This MVCHandler is responsible for executing the real processing of the application. MVCHandler implements IHTTPHandler interface that contains the ProcessRequest method to process a further request. When an instance of the Controller class is created it calls the execute method of the Controller class.

The second phase of this step in MVC Life Cycle is to send the final response as an output to the View.

Step 5- Invoke Action:

After the instance of the Controller class is created the next major step is to choose right Action method. The ActionInvoker class is responsible for choosing right Action method and executing. The ActionInovker class implements IActionInterface that has InvokeAction method.

Step 6- Return Result.

After the execution of action method in the previous step, the action method prepares the appropriate result and return the response data. This response data can be of any type such as ViewResult, ContentResult, JsonResult etc.

Conclusion:

Hope you understand the Life Cycle of ASP.NET MVC. I would like to have your feedback, Comments and your suggestions.

View More:

Thank You.

11 Comments

  • Whats Going down i am new to this, I stumbled upon this I’ve found It positively useful and it has aided me out loads. I hope to give a contribution & help other customers like its aided me. Good job.

  • Hello! I simply want to give you a big thumbs up for the great info you have got right here on this post.

  • I know this site gives quality based articles or reviews and additional stuff, is there any other site which gives these data in quality?

  • I do not even know how I stopped up right here, but I assumed this submit was once good. I do not know who you’re but definitely you are going to a famous blogger in case you aren’t already.

  • I’ve been browsing on-line more than 3 hours lately, but I never discovered any interesting article like yours. It is pretty value enough for me. In my opinion, if all website owners and bloggers made excellent content as you did, the web might be a lot more helpful than ever before.

  • Right now it sounds like Movable Type is the preferred blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?