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

如何在ASP.NET MVC中记录未处理的异常?

发布时间:2020-12-16 04:21:15 所属栏目:asp.Net 来源:网络整理
导读:这是我在Global.asax.vb中尝试做的事情: Public Class MvcApplication Inherits System.Web.HttpApplication Shared Sub RegisterRoutes(ByVal routes As RouteCollection) routes.IgnoreRoute("{resource}.axd/{*pathInfo}") routes.MapRoute( _ "Error",_
这是我在Global.asax.vb中尝试做的事情:
Public Class MvcApplication
    Inherits System.Web.HttpApplication

    Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
        routes.MapRoute( _
            "Error",_
            "error.html",_
            New With {.controller = "Error",_
                      .action = "FriendlyError"} _
        )
        ...
        'other routes go here'
        ...
    End Sub

    Sub Application_Start()
        RegisterRoutes(RouteTable.Routes)
    End Sub

    Sub Application_Error(ByVal sender As Object,ByVal e As EventArgs)
        ...
        'code here logs the unhandled exception and sends an email alert'
        ...
        Server.Transfer("http://www.example.com/error.html")
    End Sub

End Class

但是Server.Transfer失败了:

Invalid path for child request 'http://www.example.com/error.html'. A virtual path is expected.

我该如何解决?或者,对我来说这是一个更好的方法吗?

解决方法

我刚刚在Scott Hanselman的博客 here上找到了这个名为 ELMAH的错误记录器/处理程序,您可以使用它而无需更改代码.您可能想要研究它,因为它似乎与MVC很好地协作.

(编辑:李大同)

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

    推荐文章
      热点阅读