从 Application_OnError 获取正确的 Response.StatusCode (ASP.NET MVC)
我正在尝试为 ASP.NET MVC 应用程序中的未处理异常创建一些基本日志记录,但由于我使用的是 IIS6,所以所有请求都通过 .NET 进行。 现在,虽然我同意丢失的图像是需要标记的重要事项,但它们并不是阻碍因素,因此我想将 404 的事件优先级设置为高,除非它们是图像(将获得中等优先级)。
问题是,在Application_OnError
中,Response.StatusCode
是200,但最终发送出去的结果是404。为此,我似乎无法观看为 404 设置适当的优先级。
有没有办法知道StatusCode
将会是什么?
I'm trying to create some basic logging for unhandled exceptions in my ASP.NET MVC application, but as I'm using IIS6 all requests come through .NET. Now while I agree that missing images are an important thing to flag, they aren't show-stoppers and so I'd like to set the event priority to high for 404s unless they are images (which will get medium priority).
The problem is that in Application_OnError
the Response.StatusCode
is 200, but the final result sent out is 404. To this end, I don't seem to be able to watch out for 404s to set the appropriate priority.
Is there a way to tell what the StatusCode
is going to be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过 Context.Server.GetLastError() 获取它:
You can get it via
Context.Server.GetLastError()
:我想你必须将所有流量发送到 .net isapi 层并自己进行手动 404 检查(如果文件存在)
You would have to send all traffic through to the .net isapi layer and do a manual 404 check yourself (if file exists) I would imagine