.NET MVC Request Life Cycle

Why you want to know MVC Life Cyle

When I first time get involved in .NET MVC projects, I feel a bit lost because there are so many things behind the scenes. After some time, by hands on practice, I feel MVC is quite handy compared to WEBForms, but still not quite clear about the overall request life cycle. After some researches, I finally understand the whole request life cycle. So I blog it out to share with you so that you only need to research on what you don’t know. Hopefully this blog can save your time on researching a lot to find out what you don’t know.

MVC life cycle in detail

Basically, the image shows the common steps for MVC request. When a request comes, IHttpModules manipulate the request and (RouteModule)map the request to what the IHttpHandler can understand. Then IHttpHandler will create controller, invoke action and generate response base on the mapping. If are interested in details of some of the steps mentioned in this image, you may refer to this: .NET MVC Request Life Cycle.

Action life cycle in detail

The above flow does not include details about how an action is invoked,executed, and generate response based on the action return type. Here is the detailed flow:

Action Life CycleAction Life Cycle

Note:

1. All action filters are optional, depends on your need.

2. There is one more filter called ExceptionFilter, which is used to handle exception in     action.

3. In some articles, action filter is specifically for ActionFilter. While some other articles use     action filter to refer all filters mentioned above

4. You can customise your own view engine or add view engines(http://  www.codeproject.com/Articles/294297/Creating-your-own-MVC-View-Engine-into-MVC-Applica).

Summary, .Net MVC is highly flexible in every stage of the request. It allows you to customise most of the stages. For most of the cases, the default function will most likely fulfil your needs.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s