1
在我的應用程序中,我使用「HandleError」,如果發生錯誤,我的「Error.vbhtml」視圖呈現。這很好,除了現在我還想記錄錯誤。我已經構建了一個自定義的HandleError類,繼承了HandleErrorAttribute,並重寫了OnException方法。ASP.NET MVC覆蓋HandleError導致查看不呈現
現在我的錯誤得到記錄,但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
嘗試調用'base.OnException()'你完成之後登錄? [黑暗中射擊],另外'HandleError'不是有史以來最好的選擇。屬性應該始終以名稱「Attribute」結尾,並且可能不會與它們繼承的類共享名稱(即使它們位於不同的名稱空間中)。 – 2010-11-16 22:05:47