17
votes

I went through http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana and was wondering what is the difference between HTTP module and owin middleware. Some pointers that i can think of are

1) Owin middleware decouples the application from host/server. So that it is no longer necessary for me to hook my application logic specifically to System.Web

2) Owin middleware are executed in the order they are added ( not sure if the same holds true for HttpModules; may be depends on how i have added them in web.config)

3) HttpModules helps me to attach my code specific to a application events. Owin middleware is independent of these events

Please also let me know of practical example of using a OWIN module and not a HttpModule.

Some more links i ended up reading (i'll keep on adding here as and when i encounter new) http://www.cloudidentity.com/blog/2013/07/23/securing-a-web-api-with-windows-azure-ad-and-katana/

Update : perhaps this has the anwer i was looking for http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline

When should I use OWIN Katana?

Thanks.

1

1 Answers

20
votes

1) and 3) is correct, 2) is true for HttpModules as well, so no difference. The point is that OWIN doesn't have the very complex infrastructure of ASP.NET requests, and it's host independent. In fact, you can host OWIN applications inside another .NET application if you so desire.

As far as I'm concerned, if you're going with a modern infrastructure, built on ASP.NET MVC, WebApi or such, forget HttpModules. They're part of an infrastructure built ages ago, and for very different problemes than those modern web developers face. It's also usually a lot easier to integrate different services under OWIN (and the built-in OAuth authentication and similart hings are quite handy).

Now, if you're still developing web applications using the "old" WebForms model, HttpModules migth still be a better choice - hosting WebForms in OWIN is possible (and probably works well), but the benefits kind of disappear. However, if you want a thin HTTP end-point, OWIN is just awesome; it's very lightweight and simple compared to the old ASP.NET infrastructure. The fact that it isn't tied strongly to IIS is just a cherry on top. Personally, I still use it with IIS, although I can definitely see a use for a light-weight HTTP server inside a different service. Also, don't forget that IIS version is tied to Windows version - using all the latest features often needs a server upgrade on IIS.