Introduction
The ASP.NET Core MVC Request Life Cycle is a sequence of events, stages or components that interact with each other to process an HTTP request and generate a response that goes back to the client. In this article, we will discuss each and every stage of ASP.NET Core MVC Request Life Cycle in detail.

The request life cycle consists of various stages which are:
Middleware
Middleware component forms the basic building block of application HTTP pipeline. These are a series of components that are combined to form a request pipeline in order to handle any incoming request.
Routing
Routing is a middleware component that implements MVC framework. The routing Middleware component decides how an incoming request can be mapped to Controllers and actions methods, with the help of convention routes and attribute routes.
Controller Initialization
At this stage of ASP.NET MVC Core Request Life Cycle, the process of initialization and execution of controllers takes place. Controllers are responsible for handling incoming requests. The controller selects the appropriate action methods on the basis of route templates provided.
Action method execution
After the controllers are initialized, the action methods are executed and returns a view which contains Html document to be returned as response to the browser.
Result Execution
During this stage of ASP.NET MVC Core Request Life Cycle, result i.e. the response generated to the original HTTP request, is executed. If an action method returns a view result, the MVC view engine renders a view and returns the HTML response. If result is not of view type, then action method will generate its own response.
Now, we will discuss each stage briefly
Middleware
Middleware component forms the basic building block of the application'a HTTP pipeline. These are aseries of components that are combined to form a request pipeline in order to handle any incoming request. Whenever a new request comes, it is passed to the first middleware component. The component then decides, whether to generate a response after handling that incoming request or to pass it to the next component. The response is sent back along these components, once the request has been handled.
Most middleware components are implemented as standalone classes, which are content generating middleware. Now, we will be creating a content generating middleware component by adding ContentComponent.cs class.
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace WebApplication
{
public class ContentComponent
{
private RequestDelegate nextComponent;
public ContentComponent(RequestDelegate nextMiddleware) => nextComponent = nextMiddleware;
public async Task Invoke(HttpContext httpContext)
{
if (httpContext.Request.Path.ToString().ToLower() == "/edit")
{
await httpContext.Response.WriteAsync("This is edit URL component", Encoding.UTF8);
}
else
{
await nextComponent.Invoke(httpContext);
}
}
}
}
This ContentComponent middleware component is defining a constructor, and inside constructor its taking RequestDelegate object. This RequestDelegate object represents the next middleware component. ContentComponent component also defines an Invoke method. When ASP.NET Core application receives an incoming request, the Invoke method is called.
The HttpContext argument of the Invoke method provides information about the incoming HTTP request and the generated response that will be sent back to the client. The invoke method of ContentComponent class checks whether incoming request is sent to /edit URL or not. If the request has been sent to /edit url then, in response a text message is sent.
Routing
Routing is a middleware component that implements MVC framework. In ASP.NET Core, the routing system is used to handle MVC URLs. The routing Middleware component decides how an incoming request can be mapped to Controllers and actions methods, with the help of convention routes and attribute routes. Routing bridges middleware and MVC framework by mapping incoming request to controller action methods.
In a particular application, MVC registers one or more routes using MapRoute method. MVC provides default routes that are given a name and a template to match incoming request URLs. The Controllers and action variables are placeholders that are replaced by matching segments of the URL.
These routes are passed into and consumed by routing middleware.
The MVC routing pipeline

In ASP.NET Core, routing maps an incoming request to RouteHandler class, which is then passes as the collection of routes to the routing middleware. The routing middleware executes MVC RouteHandler for each route. If a matching controller and action method is found on a particular route, then the requested data is forwarded to the rest of the MVC framework which will generate a response.
There are two types of routing available in MVC which are:
Convention routing
This routing type uses application wide patterns to match a different URL to various controller action methods. Convention routes represent default possible routes that can be defined with the help of controller and action methods.
Attribute routing
This type of routing is implemented through attributes and applied directly to a specific controller or action method.
The convention routing methodology is implemented inside startup.cs file. In startup.cs, the UseMvc() method registers the routes, that are being supplied to it as a parameter inside MapRoute method.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
A route attribute is defined on top of an action method inside controller class.
public class MoviesController: Controller {
[Route(“movies / released / {year}/{month:regex(\\d{4})}”)]
public ActionResult ByReleaseYear(int year, int month) {
return Content(year + ”/”+month);
}
}
Controller Initialization
At this stage, the process of initialization and execution of controllers takes place. Controllers are responsible for handling incoming requests which is done by mapping request to appropriate action method. The controller selects the appropriate action methods (to generate response) on the basis of route templates provided. A controller class inherits from controller base class. A controller class suffix class name with the Controller keyword.

The MVC RouteHandler is responsible for selecting an action method candidate in the form of action descriptor. The RouteHandler then passes the action descriptor into a class called Controller action invoker. The class called Controller factory creates instance of a controller to be used by controller action method. The controller factory class depends on controller activator for controller instantiation.
After action method is selected, instance of controller is created to handle request. Controller instance provides several features such as action methods, action filters and action result. The activator uses the controller type info property on action descriptor to instantiate the controller by name. once the controller is created, the rest of the action method execution pipeline can run.
The controller factory is the component that is responsible for creating controller instance. The controller factory implements an interface called IControllerFactory. This interface contains two methods which are called CreateController and ReleaseController.
Action Method Execution Process
Authorization Filters
Authorization filters authorize or deny any incoming request.
Controller Creation
Instantiate Controller object.
Model Binding
Model Binding bind incoming request to Action method parameters.
Action Filters
OnActionExecuting method is always called before the action method is invoked.
Action Method Execution
Action method inside controller classes executes logic to create Action Result. Action method returns action results to generate response.
Action Filters
OnActionExecuted method called is always called after the action method has been invoked.
Authorization Filters
In ASP.NET Core MVC, there is an attribute called Authorize. Authorize is a filter, which can be applied to an action and it will be called by a MVC Core framework before and after that action or its result are executed.

kaushik ghoshPosted Dec 14, 2021, 3:19 AM
Perfectly define each stages of MVC Core Life cycle
Bhushan GuptaPosted Aug 18, 2020, 1:05 PM
Perfect for anybody who want to learn process of MVC Core
Javad NorouziPosted Jul 18, 2020, 2:29 AM
Fantastic. very nice description. Brief and complete
Jerald James CapaoPosted Jan 24, 2020, 4:18 PM
Well-explained and it helped me a lot in starting my ASP.NET Core journey. Thank you!
Sarathlal SaseendranPosted Jan 17, 2020, 6:01 PM
Good one Abhishek
Sourav Kumar DasPosted Jan 17, 2020, 10:55 AM
Nice and useful article. Thanks for sharing.
Hamid KhanPosted Jan 17, 2020, 10:28 AM
Good explanation , but to lengthy
Pritesh MaturkarPosted Jan 17, 2020, 9:12 AM
It is nice article.
Ankur MistryPosted Jan 17, 2020, 9:09 AM
Good stuff, thanks for sharing