How to fix – HTTP Headers – Always return 200 code

Tags: IIS

I found an article that explains in further detail how to make the "404 Not Found" show-up even when using a custom error page.  You need to add <% response.status = "404 Not Found" %> to your custom 404 webpage and the appropriate status code is returned. tool.

'Here is a link to the article

'Status codes KB article.


  • Hannes Preishuber said

    please dont use response.status = "404 Not Found"
    its at least against all globalization rules. I would suggest to put the code in load event ( thats where everybody is expecting it) and use the Statuscode

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Response.StatusCode = "404"
    End Sub

    ps: i have no idea why but i can not use IE7 to comment your blog

  • http:// said

    I would report the bug to or send me an email at steve AT I'll report the problem. Can you tell me what version of OS you are running? Do you get any errors? What happens when you try, a popup box? JavaScript error?

  • Wim Hollebrandse said

    Err…Steve, surely using the HttpStatusCode enumeration is better than setting the Status string:

    Response.StatusCode = (int)HttpStatusCode.NotFound;

    Also – Hannes, the StatusCode is of type Int32, so your VB.NET example won't compile.

  • Phil Winstanley said

    It's bad practice to use any kind of dynamic page as your error page – if ASP.NET is failing or something in your request stack is erroring the error page could also cause it to error.

    Instead point to a .html file on disk with appropriate links.

    Oh and it's the Technorati script which is breaking the comments in IE7, I had exactly the same issue.

  • Wim Hollebrandse said

    Phil – it's all well and good pointing to a static and generic error page, but the whole point of custom errors in ASP.NET is exactly to use dynamic pages. Why else would we have a Server.GetLastError()?

    Simply pointing to a generic error page in that instance would also not give you the appropriate error logging and notification that you would have when serving up a dynamic error page.

    Also – taking your argument a step further, one might as well say: "What if IIS is down…?"… 😉

  • steve schofield said

    Thanks Plip for telling me how to solve the issue. I removed the section, hopefully this will allow people post comments. I didn't find much on this topic, so I thought I would post what worked for one person. the additional information will help people looking for a solution.

  • steve schofield said

    I disagree about not using a dynamic page for a 404 / 500 error. This helps many times to make a site better, by logging errors. I suppose it depends on what site, but for the ones I've done, having a dynamic error page makes more sense.

Add a Comment