This great article explains things about ASP.NET 5 Middleware, Or Where Has My HttpModule Gone?
But it is still unclear about when and why we have to use ASP.NET 5 Middleware.
Can anyone explain it and provide real life examples of its usage?
This great article explains things about ASP.NET 5 Middleware, Or Where Has My HttpModule Gone?
But it is still unclear about when and why we have to use ASP.NET 5 Middleware.
Can anyone explain it and provide real life examples of its usage?
It's actually quite simple. You would create a middleware to get a hold of a request and decide:
You can also have a middleware to act on the responses only (e.g. a middleware who does the compression).
Most of the middlewares are to provide cross cutting functionality such as routing, authentication, compression, error handling. A few real world examples on these:
One confusion could be around framworks here such as MVC, SignalR, etc.. Previously in Katana world, each framework was creating each own middleware to hook into the system. With ASP.NET 5, this is a little different. In order for a framework to process requests, you can hook into the routing middleware by providing a special handler. For example, here is the MVC 6 route handler. When you look at the biuilder extensions, you will see that MVC actually uses the routing middleware.