gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 04:51:28 24 4
gpt4 key购买 nike

这里遇到一个奇怪的问题。大家都知道,如果你使用 web.config 的 customErrors部分来制作自定义错误页面,您应该设置 Response.StatusCode任何适当的事情。例如,如果我制作一个自定义 404 页面并将其命名为 404.aspx,我可以输入 <% Response.StatusCode = 404 %>以便使其具有真正的 404 状态 header 。

到目前为止还关注我吗?好的。现在尝试在 IIS7 上执行此操作。我无法让它工作,期间。如果Response.StatusCode在自定义错误页面中设置,IIS7似乎完全覆盖了自定义错误页面,并显示了自己的状态页面(如果您配置了)。

还有其他人看到过这种行为并且可能知道如何解决它吗?它在 IIS6 下运行,所以我不知道为什么事情发生了变化。

注意:这与ASP.NET Custom 404 Returning 200 OK Instead of 404 Not Found中的问题不同。

最佳答案

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

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

existingResponse 属性的默认值为 Auto:

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.

更多信息:What to expect from IIS7 custom error module

关于asp.net - IIS7 在设置 Response.StatusCode 时覆盖 customErrors?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/434272/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com