title: ASP.Net 4: Custom error pages with correct HTTP status code, how?
body: <p>I'm running a ASP.Net 4 site on Windows 2008 R2 with IIS 7.5.</p>
  
  <p>When developing I use windows 7 and VS 2010 with IIS 7.5 as well.</p>
  
  <p>I've setup my web.config as such:</p>
  
  <pre><code>&lt;customErrors mode="On" defaultRedirect="~/Error500.aspx" redirectMode="ResponseRewrite"&gt;
    &lt;error statusCode="404" redirect="~/Error404.aspx"/&gt;
  &lt;/customErrors&gt;
  </code></pre>
  
  <p>And my Error404.aspx page has this in its code-behind:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      Response.StatusCode = 404;
  }
  </code></pre>
  
  <p>On my developer machine this works fine, I see my pretty errorpage in the browser, and using Fiddler I can confirm I only receive the 404 HTTP status.</p>
  
  <p>Now when I publish it to my server, it's a different story. Here I'll see the IIS' own 404 page ("C:\inetpub\custerr\en-US\404.htm")</p>
  
  <p>If I remove the Response.StatusCode in my code-behind, I get the errorpage fine on the server, albeit with a 200 HTTP status.</p>
  
  <p>What am I overlooking since this doesn't work ?</p>