我想知道在通过HttpApplication.Error事件处理错误后,ASP.NET请求生命周期的哪些部分发生.具体来说,哪个事件在
http://msdn.microsoft.com/en-us/library/bb470252.aspx#Stages火灾发生错误后列出?我知道EndRequest仍然触发,我怀疑PreSendRequestHeaders和PreSendRequestContent也是一样的,但除此之外我不知道.
这是否取决于在生命周期中什么时候发生错误?这是否取决于我是否在错误处理程序中调用Server.ClearError()?
我问这个问题,因为我不知道我是否应该从我的错误处理程序调用HttpApplication.CompleteRequest().
解决方法
最好的方法是捕获服务器最后一个错误和appdomain异常.
所有这些都可以在Global.asax.cs文件中完成.
请检查以下步骤:
1-在Global.asax.cs中,捕获最后一个错误并记录它.
protected void Application_Error(object sender,EventArgs e) { Exception exception = Server.GetLastError(); Server.ClearError(); log.Error("Application Error caught in Global ",exception); }
2-在AppDomain上添加UnhandledException事件的事件处理程序,这应该被添加到Application_Start中:
protected void Application_Start(object sender,EventArgs e) { //.... AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); }
3-这里是CurrentDomain_UnhandledException的实现:
void CurrentDomain_UnhandledException(object sender,UnhandledExceptionEventArgs e) { if (e != null) log.Error("Domain Unhandled Exception: ",e.ExceptionObject as Exception); }
快乐编码:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。