Search This Blog

HttpModule vs Owin MiddleWare

What is HttpModule

ASP.NET HttpModule is a special piece of code which have complete access to your Http request coming from client once handed over by IIS to ASP.NET and v.v. HttpModule code is called on every request that is made to your application. It can intercept HttpRequest and act on it based on the request. Because of this nature they are part of ASP.NET pipeline. HTTP modules let you examine incoming and outgoing requests and take action based on the request.

You can hook your module logic using concrete implementation (Create a class that implements the IHttpModule interface) of IHttpModule interface. Once you register your module you will have complete access of your application & its events inside IHttpModule.Init method. This way you can drive behavior of your ASP.NET application.


More or less you can achieve the same behavior in Global.ascx.cs file but HttpModule provides greater separation of concern and componentization. Same piece of code can be used among multiple applications by separating it into Dll. Later you can register that Dll into multiple applications.



What is OWIN Middleware

As per definition provided by the OWIN specification, Middleware is:


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.

OWIN allows chaining together middleware into a pipeline. A web framework can interact with OWIN without knowing whether it is interacting directly with the underlying web server, or with one or more layers of middleware (each implementing OWIN) on top of the web server.


HttpModule vs Owin MiddleWare


  • Owin middleware decouples the application from host/server (IIS). 
  • You need not to hook application logic specifically to System.Web which is very tightly coupled with IIS.
  • HttpModules allows to attach code specific to an application event. OWIN middleware is independent of these events.
  • Event-driven approach has been replaced with a composable model.