ASP.NET Core Pipeline

Good to know how many steps your request will pass until reaches your code!

ASP.NET Core is highly customizable and it's possible to change request behavior by using Middleware.

When we say changing request road by using Middleware thus the order of them matters, by knowing these possibilities, it's easy to organize your code.

In this image, I excluded the outer parts like DNS resolvers but this is the main gist of the pipeline.

Keep in mind, all your API stuff like Actions or Endpoints are in one middleware, remember when calling app.UseControllers() actually this is a middleware, and guess what? all ActionFilters or EndPointFilters are executing inside that middleware!

For example, you can see almost all built-in ASP.NET core middleware, it's valid to say when you see app.Use* means it's going to add a new middleware to the pipeline.

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseMigrationsEndPoint();
}
else
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
// app.UseCookiePolicy();

app.UseRouting();
// app.UseRateLimiter();
// app.UseRequestLocalization();
// app.UseCors();

app.UseAuthentication();
app.UseAuthorization();
// app.UseSession();
// app.UseResponseCompression();
// app.UseResponseCaching();

app.MapRazorPages();
app.MapDefaultControllerRoute();

app.Run();

I always like to know the pipeline not only ASP.NET but also all other frameworks I use.

1
An error has occurred. This application may no longer respond until reloaded. Reload x