.net – Application_Error不会触发?
发布时间:2020-05-25 05:23:40 所属栏目: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){
|
在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 – HttpContext.Current.User!= HttpContext.User
- asp.net-mvc – ASP.NET MVC – 使用Moq框架对RenderPartia
- ASP.net缓存绝对到期不工作
- 如何在服务器控件属性中使用ASP.NET %=标签?
- 如何使用WebAPI没有ASP.NET MVC?
- asp.net – Web发布的密码不同于我的Azure管理员密码?
- asp.net – 无法返回JsonResult
- asp.net – DNN vs Composite C1 – Pro and Cons
- asp.net-mvc – 使用Angular VS Razor进行ASP.Net MVC验证
- asp.net-mvc-3 – 带有asp.net mvc 3的$ajax内的相对URL
