加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – Application_Error已调用,但没有异常

发布时间:2020-12-16 03:48:19 所属栏目:asp.Net 来源:网络整理
导读:在VS2010 SP1中调试我的MVC 4应用程序时,调用了Application_Error()处理程序,但Server.GetLastError()为null. protected void Application_Error(){ var exception = Server.GetLastError(); // exception is null. How is that possible?} MSDN states Appl
在VS2010 SP1中调试我的MVC 4应用程序时,调用了Application_Error()处理程序,但Server.GetLastError()为null.

protected void Application_Error()
{
    var exception = Server.GetLastError();
    // exception is null.  How is that possible?
}

MSDN states Application_Error是

called if an unhandled exception occurs anywhere in your … application… You can get information about the most recent error from the GetLastError method.

Server.GetLastError()的MSDN文档说明

Return value: The previous exception that was thrown.

我怎么可能处于调用Application_Error()但Server.GetLastError()返回null的状态?

解决方法

您是否在web.config中使用自定义错误处理?我相信如果浏览器发出重定向,之前的异常将会丢失.拿一个 look at this answer,看看你的情况是否相似.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读