.net – Application_Error不会触发?
发布时间:2020-12-15 23:58:08 所属栏目:asp.Net 来源:网络整理
导读:在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
在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事件处理程序.相反,我得到一个运行时错误页面. 在抛出异常后,我需要做什么才能调用Application_Error? 解决方法
它看起来很好,应该调用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"); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 如何在MVC 5中使用用户身份中的角色
- ASP.NET的登录控件问题
- 在子文件夹中运行MVC的Asp.net WebForms应用程序
- asp.net-mvc – ASP.NET MVC Preview 5 on Mono
- 使用带有自定义角色提供程序的asp.net mvc 4登录失败时,错误
- asp.net – 存储过程查询中的SQL注入
- asp.net-mvc-3 – ASP.NET MVC ActionFilter – 确定是否AJ
- asp.net核心 – ASP.NET 5,DNX&Kestrel:没有打破点
- asp.net-mvc – asp.net mvc3 jquery ui对话框和客户端验证
- asp.net-mvc – ASP.net MVC验证钩
推荐文章
站长推荐
- Asp.net Mvc表单验证气泡提示效果
- asp.net-mvc-3 – StructureMap初学者|物业注入
- asp.net – 在Publish上自动压缩html和css?
- asp.net-mvc-3 – 是否可以在Javascript文件中使
- asp.net-mvc – 在DataAnnotations DataType Att
- asp.net-mvc – 如何在ASP.NET MVC的下拉列表中发
- asp.net mvc和sql查询
- asp.net – SQL Reporting Services – 打印按钮
- asp.net-mvc – Font Awesome在优化和CDN时无法在
- asp.net-mvc – ASP.NET MVC中的Razor页面生命周
热点阅读