Middleware in action

In the previous section, we looked into a pictorial representation of the middleware request pipeline processing. In this section, you will learn the role of middleware in the request pipeline by writing a code.

Create an Empty ASP.NET Core application and comment out/remove the default code in the Configure method of the Startup class.

We will write a code to understand the four extension methods from the previous section: Use(), Run(), Map(), and MapWhen() of IApplicationBuilder.

The middleware components accept the RequestDelegate method. They are the functions that process the HTTP request with a signature as follows:

    public delegate Task RequestDelegate(HttpContext context); 

It takes in one parameter of HttpContext ...

Get Mastering ASP.NET Web API now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.