This article will help you understand what is middleware in ASP.NET Core applications and how they really work. It will also help you learn how you can create your own middleware and plug it in-between.
So, to start, let's see,
So, to start, let's see,
What is a middleware (in context of ASP.NET Core)
The definition of "Middleware" varies widely depending on its context, but in relation to ASP.NET 5, the definition provided by the OWIN specification seems closest: "Pass through components that form a pipeline between a server and application to inspect, route, or modify request and response messages for a specific purpose."
Middleware are application components which are assembled into an application pipeline to handle requests and responses, and collectively known as middleware. Each component can choose whether to pass the request on to the next component in the pipeline, and can perform certain operations before and after the next component in the pipeline. Request delegates are used to build this request pipeline, which are then used to handle each HTTP request to your application.
ASP.NET 5 has integrated support for middleware. Configure method in Startup class allows you wire up any middleware of your choice.
Let me show you what that exactly means:

Each component has a job to perform when the component receives a request. Each component can perform some work and optionally pass the request to the next component. Each HTTP transaction can visit each piece of middleware once on the way in, and once on the way out. It effectively replaces the functionality that was formerly covered by things like HttpModules and HttpHandlers.

Each component has a job to perform when the component receives a request. Each component can perform some work and optionally pass the request to the next component. Each HTTP transaction can visit each piece of middleware once on the way in, and once on the way out. It effectively replaces the functionality that was formerly covered by things like HttpModules and HttpHandlers.
Request delegates are configured using Run, Map, and Use extension methods on the IApplicationBuilder type that is passed into the Configure method in the Startup class. An individual request delegate can be specified in-line as an anonymous method, or it can be defined in a reusable class. These reusable classes are middleware, or middleware components. Each middleware component in the request pipeline is responsible for invoking the next component in the chain, or choosing to short-circuit the chain if appropriate.
PS:
A Middleware component, in an ASP.NET Core project, is a class like any other. The difference is that the Middleware component needs to have a private property of type RequestDelegate,
A Middleware component, in an ASP.NET Core project, is a class like any other. The difference is that the Middleware component needs to have a private property of type RequestDelegate,







Michael GriffithsPosted Apr 10, 2016, 10:13 AM
Nice share
NitinPosted Apr 10, 2016, 1:23 AM
good show
Manoj KulkarniPosted Apr 9, 2016, 11:31 PM
Nice article. Thank you for sharing
Vignesh ManiPosted Apr 9, 2016, 4:40 PM
Nice