在Webform1.aspx.cs中:
protected void Page_Load(object sender,EventArgs e) { throw new Exception("test exception"); }
在Global.asax.cs中:
protected void Application_Error(object sender,EventArgs e) { // Code that runs when an unhandled error occurs if (Server.GetLastError() is HttpUnhandledException) Server.Transfer("ErrUnkNown.aspx"); }
解决方法
它看起来很好,应该调用Application_Error.
您是否通过调试应用程序进行了检查?
实际上你缺少Server.ClearError()所以异常被传递给asp.net但你应该在这里压制它,因为你自己处理它.
protected void Application_Error(object sender,EventArgs e) { // Code that runs when an unhandled error occurs if (Server.GetLastError() is HttpUnhandledException) { // suppressing the error so it should not pass to asp.net Server.ClearError(); Server.Transfer("ErrUnkNown.aspx"); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。