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

这是我在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很好地协作.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....