Created On:
05/04/2007
Author:
Aaron Robson
Tags:
aspnet, custom error pages

Asp.net Custom Error Pages Must set the HttpStatusCode

When creating a custom error page in asp.net, contrary to a lot of advice out there, you probably don't want to use a static html page. The reason for this is that you need to set Response.HttpStatusCode (= 404 for example) during page processing. If you don't do this, the custom error page is shown to the user, and the status code is 200 - ie everything ok. Plainly the page couldn't be found (if its 404), but as far as a search engine is concerned, the error page is valid content for the original request. This can lead to lots of problems like pages being dropped from the index, or your robots.txt file containing the content of your error page etc.