Archief

Dev

404 and 500 pages in .NET

The web.config settings for 404 and 500 error pages are a nuisance! I’ve got the following configuration that gets me as close to my goals as I can get:

<customErrors mode="On" defaultRedirect="~/500.html" redirectMode="ResponseRewrite">
  <error statusCode="404" redirect="~/page-not-found" />
  <error statusCode="500" redirect="~/500.html" />
</customErrors>
<httpErrors errorMode="Custom" existingResponse="Replace">
  <clear />
  <error statusCode="404" subStatusCode="-1" path="/page-not-found" responseMode="ExecuteURL" />
  <error statusCode="500" path="~/500.html" responseMode="File" />
</httpErrors>

This achieves the following goals:

But unfortunately there’s more neccessary features missing:

The second problem can be fixed by loading the translated values via Ajax. If the ajax request also fails, the fallback language is English. Otherwise you get the right language.

But how to fix the statuscode so that it returns the one I expect is a mystery for me.