7

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?

5
  • 2
    My article can't be that great if it failed to answer those points clearly enough for you ;) Commented Apr 20, 2015 at 12:11
  • @MikeBrind Your article is great. I am just refering to it :) Commented Apr 20, 2015 at 16:22
  • 1
    I just wrote an article that may help you as it has concrete examples of middleware components, and a link to real world Ruby middleware too keyoti.com/blog/… Commented Apr 23, 2015 at 3:50
  • @JimW Thank you! I will read it. Commented Apr 23, 2015 at 12:10
  • I'm voting to close this question as off-topic because "discuss this {BLOG}" Commented May 2, 2015 at 15:54

1 Answer 1

6

It's actually quite simple. You would create a middleware to get a hold of a request and decide:

  • Whether you want to process it and pass it to next middleware.
  • Whether you want to process it, generate a response and cut the request lifecyle there.

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.