Working with middlewares
As you have seen before, the Startup
class is responsible for adding and configuring middlewares in your ASP.NET Core 2.0 applications. But what is middleware? When and how do you use it and how do you create your own middlewares? Those are all the questions we are going to discuss now.
Essentially, multiple middlewares compose the functionalities of your ASP.NET Core 2.0 applications. Even the most basic functionalities such as serving up static content are performed by them, as you might have noticed by now.
Middlewares are part of the ASP.NET Core 2.0 request pipeline for handling requests and responses. When they are chained together, they can pass incoming requests from one to another and perform actions before and after the next middleware is called within the pipeline:
Using middlewares allows your applications to be more flexible and evolutive, since you can add and remove middlewares easily in the Configure
method of the Startup
class.
Furthermore, the order...