title: Advanced: How many times does HttpModule Init() method get called during application's life?
body: <p>Web application initialization is as follows:</p>
  
  <ol>
  <li>As we know when IIS receives the first request for a particular Asp.net application resource, IIS creates an instance of a <code>HttpApplication</code> (defined in <code>global.asax</code> codebehind).</li>
  <li>When this new instance is created it's initialization happens that also checks all configured HTTP modules.</li>
  <li>All modules are then instantiated and put in the application's <code>Modules</code> collection (of type <code>HttpModuleCollection</code>)</li>
  <li>modules are looped through and their <code>Init()</code> method is called (when they register for request events)</li>
  </ol>
  
  <p>As far as I understand it the above scenario happens when a web application is started/initialized (hence application start event).</p>
  
  <h2>What happens with modules?</h2>
  
  <p>Are they (re)instatiated on each request or reused from the <code>Modules</code> property on each consecutive request while the web application is alive? As I understand IIS and Asp.net they are reused through the whole life of a web application.</p>
  
  <p>If they are reused, can we assume that their <code>Init()</code> method is actually a pseudo event handler for application start event? The thing is we can't attach to application level events within http modules. But if they are being reused we could use <code>Init()</code> as application start event and do whatever we'd put in <code>global.asax</code> instead.</p>
  
  <h2>Question</h2>
  
  <p>Can we assume that module's <code>Init()</code> method is called <strong>only</strong> on application start event? Could we use this assumption to i.e. register routes for applications whose <code>global.asax</code> codebehind we can't change? <code>web.config</code> is usually accessible and we can change it the way we want.<br>
  <strong>Would this actually work?</strong></p>
  
  <h2>Additional info</h2>
  
  <p>We can check <code>HttpApplication</code> code and check its <code>InitModulesCommon()</code> method. This one actually calls <code>Init()</code> of each registered HTTP module. What is more interesting is that this method is only used by <code>InitIntegratedModules()</code> and <code>InitModules()</code> methods. Which are both used <strong>only</strong> in <code>HttpApplication.InitInternal()</code> method. This is the basis of my assumptions, but I would like to know whether someone has abused <code>IHttpModule.Init()</code> for application start event.</p>