IIS7 Overrides customErrors when setting Response.StatusCode?
IIS7 Overrides customErrors when setting Response.StatusCode?
回答1
Set existingResponse to PassThrough in system.webServer/httpErrors section:
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
Default value of existingResponse property is 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.
More information: What to expect from IIS7 custom error module
Even though, we had HttpContext.Current.Response.TrySkipIisCustomErrors = true; but that didn't work. But following this solved my issue.
回答2
The easiest way to make the behavior consistent is to clear the error and use Response.TrySkipIisCustomErrors and set it to true. This will override the IIS global error page handling from within your page or the global error handler in Application_Error.
Server.ClearError();
Response.TrySkipIisCustomErrors = true;
Typically you should do this in your Application_Error handler that handles all errors that your application error handlers are not catching.
More detailed info can be found in this blog post: http://www.west-wind.com/weblog/posts/745738.aspx
Response.TrySkipIisCustomErrors not working
Well - this is a first. First time I managed to find the answer before hitting the submit button :)
Found this IIS.net article: http://www.iis.net/configreference/system.webserver/httperrors which then lead me to find this: http://msdn.microsoft.com/en-us/library/ms690576(v=vs.90).aspx
Scroll down to the part that explains what the options for existingResponse
mean. I had mine set to Replace
which means it ignores TrySkipIisCustomErrors
completely. Changed it to Auto
and it's working.
Thanks for answering your own question, your link pointed me to the right solution: <httpErrors existingResponse="PassThrough" />
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2018-02-24 media type
2018-02-24 ActionFilterAttribute
2018-02-24 log4net写日志的时间附带时区信息
2018-02-24 JQuery常用的api[最好是系统地学习一下《锋利的JQuery》]
2018-02-24 soapui icon以及resource的理解
2017-02-24 Pascal Script