title: ASP.NET Application hosted on IIS7 that is ignoring custom errors and falls back to IIS errors
body: <p>I have a C# web forms ASP.NET 4.0 web application that uses Routing for URLs for some reason custom errors defined in the system.web section of my web.config is entirely ignored and it will fall back the IIS errors.</p>
  
  <p>This gets entirely ignored</p>
  
  <pre><code>  &lt;system.web&gt;
      &lt;customErrors mode="On"&gt;
        &lt;error statusCode="500" redirect="~/Error" /&gt;
        &lt;error statusCode="404" redirect="~/404" /&gt;
        &lt;error statusCode="403" redirect="~/Error" /&gt;
      &lt;/customErrors&gt;
    &lt;/system.web&gt;
  </code></pre>
  
  <p>This part takes over</p>
  
  <pre><code>  &lt;system.webServer&gt;
      &lt;httpErrors&gt;
        &lt;!--&lt;clear /&gt;--&gt;
        &lt;remove statusCode="500" subStatusCode="-1" /&gt;
        &lt;remove statusCode="404" subStatusCode="-1" /&gt;
        &lt;error statusCode="404" subStatusCode="-1" path="/App1/404" responseMode="Redirect" /&gt;
        &lt;error statusCode="500" prefixLanguageFilePath="" path="/App1/Error" responseMode="Redirect" /&gt;
      &lt;/httpErrors&gt;
    &lt;/system.webServer&gt;
  </code></pre>
  
  <p>This would be a minor inconvenience except that by the fact it falls back to IIS native instead of my application it completely circumvents Elmah logging my 404 exceptions correctly.</p>
  
  <p><strong>Edit:</strong> Just to avoid any suggestions of such I only added the httpErrors configuration after customErrors stopped working so I would have anything.</p>