I’m trying to determine the best way to implement a 404 page in a standard ASP.NET web application. I currently catch 404 errors in the Application_Error event in the Global.asax file and redirect to a friendly 404.aspx page. The problem is that the request sees a 302 redirect followed by a 404 page missing. Is there a way to bypass the redirect and respond with an immediate 404 containing the friendly error message?
Does a web crawler such as Googlebot care if the request for a non existing page returns a 302 followed by a 404?
Handle this in your Global.asax’s OnError event:
In you error page, you should ensure that you’re setting the status code correctly:
You can also handle the various other error codes in here quite nicely.
Google will generally follow the 302, and then honour the 404 status code – so you need to make sure that you return that on your error page.