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    
posted @   ChuckLu  阅读(73)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.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
点击右上角即可分享
微信分享提示