404 error page returning a 200 response code

Jan 21, 2009 at 8:39 PM
When I went to check my webmaster settings in google webmaster tools my site was no longer verified. I just recently enabled custom errors, so it has something to do with that. When I try to re-verify I get the following error.

Verification status: NOT VERIFIED
We've detected that your 404 (file not found) error page returns a status of 200 (Success) in the header.

In my web.config I have the following section which I setup

    <customErrors mode="On">
            <error statusCode="404" redirect="/error404.aspx" />

When I enter non-existent urls it redirects to the custom 404 page, but the page itself returns a 200 code status. If I add the following to the page

In the page load of custom 404 page
  Response.AppendHeader("Status", "File Not Found");
  Response.StatusCode = 404;

It redirects to the server 404 error page (the ugly one that just says 404).

It seems I can either have a custom 404 page that returns a 200 code status, or I have to the default 404 page which returns a 404 code. How can I have both?

Jan 21, 2009 at 9:48 PM
That's a known problem with using the customErrors redirection in the web.config file.  I think what actually happens is if you go to a non-existant page, ASP.NET does a 302 redirect to your error404.aspx page, and then error404.aspx page returns a 200 status code.  So from Google's point of view, they might just be paying attention to the 302 status code, or maybe the 200 ... but of course neither are the 404 you want.

What you could do is not use the customErrors section in the web.config file.  Instead, use the error pages functionality built into IIS.  I think you're at a shared web host(?), where shared web hosts usually have a way to setup custom error pages in their control panel.  You can set it up so your error404.aspx page is executed when a 404 occurs.  In your error404.aspx page, you can set Response.StatusCode = 404.  With this approach, there should only be one single 404 response code returned ... instead of a 302 followed by a 200.
Jan 21, 2009 at 11:21 PM
I have another site that is on a different host, and it has the same web.config settings and error page settings and I'm not running into that problem. I guess it's a IIS hosting issue. IIS is such a pain... Thanks Ben.