IIS7 在设置 Response.StatusCode 时覆盖 customErrors?

IIS7 Overrides customErrors when setting Response.StatusCode?(IIS7 在设置 Response.StatusCode 时覆盖 customErrors?)

本文介绍了IIS7 在设置 Response.StatusCode 时覆盖 customErrors?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个奇怪的问题.每个人都知道,如果您使用 web.config 的 customErrors 部分来制作自定义错误页面,您应该将您的 Response.StatusCode 设置为适当的值.例如,如果我制作一个自定义 404 页面并将其命名为 404.aspx,我可以将 <% Response.StatusCode = 404 %> 放入内容中以使其具有真正的 404状态标题.

Having a weird problem here. Everybody knows that if you use web.config's customErrors section to make a custom error page, that you should set your Response.StatusCode to whatever is appropriate. For example, if I make a custom 404 page and name it 404.aspx, I could put <% Response.StatusCode = 404 %> in the contents in order to make it have a true 404 status header.

一直跟着我?好的.现在尝试在 IIS7 上执行此操作.我无法让它工作,期间.如果在自定义错误页面中设置了 Response.StatusCode,IIS7 似乎会完全覆盖自定义错误页面,并显示自己的状态页面(如果您已配置).

Follow me so far? Good. Now try to do this on IIS7. I cannot get it to work, period. If Response.StatusCode is set in the custom error page, IIS7 seems to override the custom error page completely, and shows its own status page (if you have one configured.)

有没有其他人看到过这种行为并且可能知道如何解决它?它在 IIS6 下工作,所以我不知道为什么会发生变化.

Has anyone else seen this behavior and also maybe know how to work around it? It was working under IIS6, so I don't know why things changed.

注意:这与 ​​ASP.NET 自定义 404 返回 200 OK 而不是 404 Not Found

推荐答案

在system.webServer/httpErrors部分设置existingResponse为PassThrough:

Set existingResponse to PassThrough in system.webServer/httpErrors section:

  <system.webServer>
    <httpErrors existingResponse="PassThrough" />
  </system.webServer>

existingResponse 属性的默认值为 Auto:

Default value of existingResponse property is Auto:

Auto 告诉自定义错误模块做正确的事情.客户端看到的实际错误文本将受到影响,具体取决于 IHttpResponse::GetStatus 调用中返回的 fTrySkipCustomErrors 的值.当 fTrySkipCustomErrors 设置为 true 时,自定义错误模块会让响应通过,但如果设置为 false,自定义错误模块会用自己的文本替换文本.

Auto tells custom error module to do the right thing. Actual error text seen by clients will be affected depending on value of fTrySkipCustomErrors returned in IHttpResponse::GetStatus call. When fTrySkipCustomErrors is set to true, custom error module will let the response pass through but if it is set to false, custom errors module replaces text with its own text.

更多信息:对 IIS7 自定义错误模块的期望

这篇关于IIS7 在设置 Response.StatusCode 时覆盖 customErrors?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:IIS7 在设置 Response.StatusCode 时覆盖 customErrors?

基础教程推荐