0 notes &
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:
- The URL doesn’t change (you don’t get redirected to 500.html)
- 404 page is editable via the CMS
- The 404 page is relative to the domain name, therefore in the right language (domain.nl/page-not-found gives Dutch content, domain.fr/page-not-found French)
- The 500 page can never give a 500 error itself: it’s a static html file
But unfortunately there’s more neccessary features missing:
- The 404 and 500 pages now return a statuscode 200
- The 500 page is static, so the contents isn’t translatable
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.