Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason you're seeing the behaviour is probably that your <code>Application_Error</code> handler is correctly being invoked (and invoking your controller), but then IIS is intercepting the 500 error and displaying its own error page. (though it's also possible that your <code>Application_Error</code> handler is itself throwing an <code>Exception</code>, that's something you'll want to rule out)</p> <p>Because you want to handle all errors (e.g. the static file error you mentioned), you will likely be unable to rely on either ASP.NET or ASP.NET MVC to do the initial error detection for you. <strong>Not all errors come from your application!</strong></p> <p>The best thing to do is to lean on IIS 7.5's error handling as much as you can, rather than try to get involved yourself too early. Let IIS do the initial error detection for you and it's much easier.</p> <p>Try putting the following in your <code>web.config</code>, replacing your existing <code>httpErrors</code> node:-</p> <pre><code>&lt;httpErrors errorMode="Custom" existingResponse="Replace"&gt; &lt;clear /&gt; &lt;error statusCode="400" responseMode="ExecuteURL" path="/Error" /&gt; &lt;error statusCode="403" responseMode="ExecuteURL" path="/Error/Forbidden" /&gt; &lt;error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" /&gt; &lt;error statusCode="500" responseMode="ExecuteURL" path="/Error" /&gt; &lt;/httpErrors&gt; </code></pre> <p>Remove the <code>customErrors</code> node entirely. It is unnecessary.</p> <p>Remember and make sure your error controller is setting the correct status code:-</p> <pre><code>public ActionResult Forbidden() { Response.StatusCode = 403; return this.View(); } </code></pre> <p>You should then be able to ditch everything apart from the logging out of your <code>Application_Error</code> handler - though I think you'd be best creating your own <code>HttpModule</code>; setting <code>runAllManagedModulesForAllRequests</code> on the modules node in your <code>web.config</code> helps you catch errors that would otherwise slip through.</p> <p>I've got this setup (though I'm personally using elmah to do the logging) running on the Azure Web Sites preview, and it's catching everything except from obviously any errors that come from failing to parse <code>web.config</code>.</p> <p>I've put a <a href="https://github.com/iaingalloway/ASP.NET-HttpErrors-Example" rel="noreferrer">full working example of using httpErrors for custom error pages up on github</a>. You can also <a href="http://httperrors-example.azurewebsites.net/Home" rel="noreferrer">see it live on azure web sites</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload