title: Custom HttpModule for IIS 7 for integrated
body: <p>I'm having troubles with a custom Error handler I built. It should be a <code>HttpModule</code>, but when I add it to my <code>web.config</code>'s <code>system.webServer/modules</code> tag, it is not initiated.</p>
  
  <p>This is my <code>web.config</code> section:</p>
  
  <pre><code>&lt;system.webServer&gt;
    &lt;modules&gt;
      &lt;add name="AspExceptionHandler" 
           type="Company.Exceptions.AspExceptionHandler, Company.Exceptions" 
           preCondition="managedHandler" /&gt;
    &lt;/modules&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>This is the code in my <code>HttpModule</code>:</p>
  
  <pre><code>using System;
  using System.Web;
  using Company.Settings;
  using System.Configuration;
  
  namespace Company.Exceptions
  {
    public class AspExceptionHandler : IHttpModule
    {
      public void Dispose() { }
  
      public void Init(HttpApplication application)
      {
        application.Error += new EventHandler(ErrorHandler);
      }
  
      private void ErrorHandler(object sender, EventArgs e)
      {
        HttpApplication application = (HttpApplication)sender;
        HttpContext currentContext = application.Context;
  
        // Gather information5
        Exception currentException = application.Server.GetLastError();
        String errorPage = "http://www.mycompaniesmainsite.com/error.html";
  
        HttpException httpException = currentException as HttpException;
        if (httpException == null || httpException.GetHttpCode() != 404)
        {          
          currentContext.Server.Transfer(errorPage, true);
        }
        else
        {
          application.Response.Status = "404 Not Found";
          application.Response.StatusCode = 404;
          application.Response.StatusDescription = "Not Found";
          currentContext.Server.Transfer(errorPage, true);
        }
      }
    }
  }
  </code></pre>
  
  <p>Could someone please explain to me what I am doing wrong, and how IIS 7 Integrated Managed Pipeline Mode works? Because most of the answers I found are about configuring <code>HttpModules</code> for IIS 6.</p>