ASP.NET MVC Override HandleError 导致视图无法渲染
在我的应用程序中,我使用“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
In my app I'm using "HandleError" whereby if an error happens, my "Error.vbhtml" view renders. This is working great, except now I want to also log the error. I've built a custom HandleError Class, Inherited the HandleErrorAttribute, and Overridden the OnException method.
Now my error gets logged, but the Error.vbhtml view doesn't get rendered... what praytell am I messing?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚在Codeplex上看了一下HandleError方法的源代码。我从那里获取了一些代码
这似乎有效
I just took a look at the source code of the HandleError method at Codeplex. I scooped some of the code from there
This appears to work