asp.netasp.net-mvc-4httpmodulehttpapplication

HttpApplication.Init vs HttpModule.Init


I am trying to understand why Init method is available in both the HttpApplication and HttpModule, and when to use one over the other.


Solution

  • You can have only one application, but you can have multiple HttpModules within one application. Modules are usually used to handle separate blocks of functionality that can be added to application (few real life examples - Elmah - handles error logging, IdentityModule - handles impersonation, etc.). Since you can attach the same module (lets say error logging) to different application (lets say MyCompany.CRM, MyComany.PublicWeb, MyComany.Intranet), it makes sense that they handle initialization on their own, intepended on application you're adding them to.