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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.