私のアプリでは、「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