如果redirectMode=“ResponseRewrite”,则错误不会重定向到 Http 处理程序
我看到类似的问题,但似乎是由于不相关的问题造成的。
在 3.5 中,我有一个自定义错误处理程序,用于记录错误并重定向用户。我的 web.config 设置如下:
<httpHandlers>
<add path="error.ashx" type="MySite.Tools.WebErrorLogger, MySite.Tools" verb="*"/>
</httpHandlers>
<customErrors mode="On" defaultRedirect="error.ashx"
redirectMode="ResponseRewrite">
</customErrors>
当redirectMode 设置为 "ResponseRedirect"
时,一切正常(但 Server.GetLastError() 为空,但这似乎是有意的)
但是,当使用 < code>ResponseRewrite,我的处理程序未被调用,我看到 ASP.Net 默认错误页面。知道我该怎么做吗?
(不幸的是,由于其他限制,我无法使用 aspx 页面或在 global.asax 中进行错误处理)
I see similar questions, but it looks like there were due to an unrelated issue.
in 3.5, I have a custom error handler that logs errors and redirects users. My web.config is set up as such:
<httpHandlers>
<add path="error.ashx" type="MySite.Tools.WebErrorLogger, MySite.Tools" verb="*"/>
</httpHandlers>
<customErrors mode="On" defaultRedirect="error.ashx"
redirectMode="ResponseRewrite">
</customErrors>
When redirectMode is set to "ResponseRedirect"
, everything works fine (but Server.GetLastError() being null but that seems to be intended)
However, when using ResponseRewrite
, my handler is not called and I see ASP.Net default error pages. Any idea on how I could do this?
(I unfortunately can't use either an aspx page or do my error handling in global.asax due to other constraints)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我过去曾问过一个非常类似的问题。
解决方案是将错误页面转换为静态 HTML 页面。
动态页面肯定有某种错误,但我找不到它。
Well, I have asked a pretty similar question in the past.
The solution was converting the error page to a static HTML page.
Surely there must be some kind of error on the dynamic page, but I could not find it.
我遇到了同样的问题,我发现显然原因是 .ashx 文件,如果你使用普通的 .aspx 它会工作,它对我有用;我仍在尝试了解如何使用 REsponseRewrite“启用”.ashx 文件扩展名,因为在我的情况下,它比使用 aspx 页面更符合逻辑。我在这里有一个关于此主题的开放线程:
http://social.msdn.microsoft.com/Forums/it-IT/aspnetit/thread/7b8f5e36-44a8-40ea-bd73-2e99a1fd42dd
i came to the same issue and ive found that apparently the reason is the .ashx file, if you use a normal .aspx it will work, it did for me; im still trying to understand how to "enable" the .ashx file extension with REsponseRewrite as it would be more logical rather than using an aspx page in my case. Ive an open thread about this topic here:
http://social.msdn.microsoft.com/Forums/it-IT/aspnetit/thread/7b8f5e36-44a8-40ea-bd73-2e99a1fd42dd
在当前的 .NET(从 4.5 开始)中,无法使用
ashx
处理程序来做到这一点。ResponseRewrite
使用HttpServerUtility.Execute
,它被硬编码为仅允许 aspx 页面或静态文件(或旧版 ASP 页面)。There is no way to do that with an
ashx
handler in current .NET (as of 4.5).ResponseRewrite
usesHttpServerUtility.Execute
which is hardcoded to only allow aspx pages or static files (or legacy ASP pages).