开发者

ASP.Net 4: Custom error pages with correct HTTP status code, how?

I'm running a ASP.Net 4 site on Windows 2008 R2 with IIS 7.5.

When developing I use windows 7 and VS 2010 with IIS 7.5 as well.

I've setup my web.config as such:

<customErrors mode="On" defaultRedirect="~/Error500.aspx" redirectMode="ResponseRewrite">
  <error statusCode="404" redirect="~/Error404.aspx"/>
</customErrors>

And my Error404.aspx page has this in its code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    Response.StatusCo开发者_运维知识库de = 404;
}

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.

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")

If I remove the Response.StatusCode in my code-behind, I get the errorpage fine on the server, albeit with a 200 HTTP status.

What am I overlooking since this doesn't work ?


Does this article by Rick Strahl help? It covers 500 errors and the TrySkipIisCustomErrors property to override the default IIS behaviour.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜