Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>*Updated April 2016</p> <p><strong>The customErrors attribute is used when the .net code is throwing an exception (404, 403, 500 etc) and the httpErrors attribute is used when IIS itself is throwing an exception.</strong></p> <ul> <li>/myfakeextensionslessurl --> httpErrors 404</li> <li>/myfakeaspsx.aspx --> customErrors 404</li> <li>/myfakeimage.jpg --> httpErrors 404</li> <li>/throw500.apx --> customErrors 500</li> <li>/throw500 --> customErrors 500</li> </ul> <p>There are a lot of pitfalls trying to configure this correctly. So if you are looking for a quick example, the best 2 options you have are:</p> <p>Example 1: Using html pages</p> <pre><code>&lt;system.web&gt; &lt;customErrors mode="RemoteOnly" defaultRedirect="/Error500.html" redirectMode="ResponseRewrite"&gt; &lt;error statusCode="403" redirect="/Error403.html" /&gt; &lt;error statusCode="404" redirect="/Error404.html" /&gt; &lt;error statusCode="500" redirect="/Error500.html" /&gt; &lt;/customErrors&gt; &lt;/system.web&gt; &lt;system.webServer&gt; &lt;httpErrors errorMode="DetailedLocalOnly" existingResponse="Auto"&gt; &lt;remove statusCode="403" /&gt; &lt;remove statusCode="404" /&gt; &lt;remove statusCode="500" /&gt; &lt;error statusCode="403" responseMode="File" path="Error403.html" /&gt; &lt;error statusCode="404" responseMode="File" path="Error404.html" /&gt; &lt;error statusCode="500" responseMode="File" path="Error500.html" /&gt; &lt;/httpErrors&gt; &lt;/system.webServer&gt; </code></pre> <p>Example 2: using aspx pages</p> <pre><code>&lt;system.web&gt; &lt;customErrors mode="RemoteOnly" defaultRedirect="/Error500.html" redirectMode="ResponseRewrite"&gt; &lt;error statusCode="403" redirect="/Error403.aspx" /&gt; &lt;error statusCode="404" redirect="/Error404.aspx" /&gt; &lt;error statusCode="500" redirect="/Error500.aspx" /&gt; &lt;/customErrors&gt; &lt;/system.web&gt; &lt;system.webServer&gt; &lt;httpErrors errorMode="DetailedLocalOnly" existingResponse="Auto"&gt; &lt;remove statusCode="403" /&gt; &lt;remove statusCode="404" /&gt; &lt;remove statusCode="500" /&gt; &lt;error statusCode="403" responseMode="ExecuteURL" path="Error403.aspx" /&gt; &lt;error statusCode="404" responseMode="ExecuteURL" path="Error404.aspx" /&gt; &lt;error statusCode="500" responseMode="ExecuteURL" path="Error500.aspx" /&gt; &lt;/httpErrors&gt; &lt;/system.webServer&gt; </code></pre> <p>And in the aspx error pages you need to do something like this (example 404 page):</p> <pre><code>&lt;% Response.StatusCode = 404; Response.TrySkipIisCustomErrors = true; %&gt; </code></pre> <p><em>Note: Using extension less urls in the customErrors section is <strong>not possible!</strong>.</em> (without hacks)</p> <p>One work around is to disable custom errors and let http errors handle the custom page. A friend has created such setup, when I find some time, I will share the code.</p> <p><strong>Background</strong></p> <p>A good custom error page will:</p> <ol> <li>Show the real exception when you visit the problem page locally</li> <li>Show a custom page when you visit the problem page remotely</li> <li>Will not redirect, but simply show the error page content (because of seo reasons)</li> <li>Will show the correct status code</li> </ol> <p>So to clarify some options in our config:</p> <ol> <li>customErrors mode="RemoteOnly". You can specify here: On, Off, RemoteOnly. On = Show always custom error pages, Off = Show always the real Error, RemoteOnly = Show locally the error, but show the custom error page remotely. So we want RemoteOnly for statement 1</li> <li>customeErrors redirectMode="ResponseRewrite". You can sepcify here: ResponseRedirect, ResponseRewrite. The modus ResponseRedirect will redirect the error page to the custom error page. For a link crawler (seo) this will result in 302 -> 500. While you want the link crawler to get just simply a 500 error.</li> <li>httpErrors errorMode="DetailedLocalOnly", this the equalivant of the customErrors mode. Options that you have: Custom, Detailed, DetailedLocalOnly</li> </ol> <p>A good blog post which helped me a lot is: <a href="http://benfoster.io/blog/aspnet-mvc-custom-error-pages">http://benfoster.io/blog/aspnet-mvc-custom-error-pages</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. 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.
    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