在我的应用程序中,我使用“HandleError”,如果发生错误,我的“Error.vbhtml”视图会呈现。这很好用,除了现在我还想记录错误。我已经构建了一个自定义 HandleError 类,继承了 HandleErrorAttribute,并重写了 OnException 方法。
现在我的错误被记录了,但是 Error.vbhtml 视图没有被渲染......我在搞什么鬼?
Imports System.Web.Mvc
Namespace Mvc.Attributes
Public Class HandleError : Inherits System.Web.Mvc.HandleErrorAttribute
Private ExceptionService As Domain.IExceptionService
Public Sub New()
ExceptionService = New Domain.ExceptionService(New Domain.ExceptionRepository)
End Sub
Public Overrides Sub OnException(ByVal exceptionContext As ExceptionContext)
''# Log the exception if it has not been handled elsewhere
If Not exceptionContext.ExceptionHandled Then
ExceptionService.AddException(exceptionContext.Exception)
ExceptionService.SubmitChanges()
''# Signal to the system that we've handled the exception
exceptionContext.ExceptionHandled = True
End If
End Sub
End Class
End Namespace