Best Approaches for Middleware
Middleware is one of the most powerful concepts in ASP.NET Core. For legacy ASP.NET developers, Middleware is a relatively new term. Before middleware, there were HTTP handlers and modules, which required separate code to configure through a web.config
. Middleware is now considered a first-class citizen in an ASP.NET application, making it easier to maintain in a single code base. First introduced in ASP.NET Core 1.0, the common request and response concepts are considered pipelines for your applications with the ability to control a request and response’s body. This opens up a number of possibilities to create amazing features for your ASP.NET Core web applications.
At the beginning of this chapter, we’ll examine how to use Middleware and some common built-in Middleware components found in almost every ASP.NET Core application. Next, we’ll examine the three request delegates (Run
, Map
, and Use
) and explain what each is used for...