ASP.NET MVC Pipeline life-cycle Part 1Beginner
MVC isn’t a programming language, it’s an architecture and a way of communication between system modules. In an MVC application the system is divided into three main modules : Model - View - Controller
What is MVC ?
MVC isn’t a programming language, it’s an architecture and a way of communication between system modules.
In an MVC application the system is divided into three main modules :
- Model : contains system and business data
- View : represents a way to display the data to users.
- Controller : represents business logic that needs to be calculated after manipulating the data. It acts as a linkage between the Model and the View
You can see a brief graph about the MVC architecture in the below image.
The HTTP request comes in. Then the controller handles the request then retrieves the data do some stuff and process those data. It Then sends the result to the view to be rendered and a response is sent back to the client.
This is MVC in a glance. We will see how the MVC works in details in the following section
ASP.NET MVC life cycle order in details:
The ASP.NET MVC Life cycle executes in the following order as shown in the image below :
- HTTP Application
- Authentication Filters
- Authorization Filters
- Authentication Challenges
- Action Execution
- Result Execution
- The Application_start() event is called
- In this stage the application initializes and the app events are registered along with ASP.NET MVC Areas, Filter and Routings.
- This is an application-wide process
- You can see the process if you click on the global.asax file in project file
If you opened the file, you can find the registration code
- Routing is the process of matching the coming request URL to the correct resource and controller
- MVC Routing is done via Routing table that is defined using MapRoute method in Application_Start function in global.asax file we discussed earlier
- If you navigated to Application_Start() function you can see this line inside the function body :
- In RouteConfig.cs file in App_Start folder you can see the code for registering the routing table
- routes.MapRoute function accepts parameters :
- Name : routing name
- Url : URL pattern to be matched
- Defaults : default values for url if they are not specified
- You can see the routing flow in the following image
In the next part, we will continue with the rest of the pipeline steps. Stay tuned.