How do I access an unhandled exception in an MVC Error view?

点点圈 提交于 2020-01-04 14:18:27

问题


When the HandleError attribute on a controller detects an unhandled exception and redirects to the Error view, I would like to provide the user with a brief description of the error, and an option to email the error to the application administrator.

I do have a custom HandleError that notifies Elmah to log the error, but having to look up the error in the Elmah log seems a bit of a last resort. Is there any other way to access the unhandled exception that is 'caught' by HandleError?


回答1:


HandleErrorAttribute supplies a Model object of type HandleErrorInfo Your Error page could look like this

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<HandleErrorInfo>" %>

The Model has an Exception property with the details of the exception handled.

I usually use a custom error handler that also logs the exception using log4net and I have an STMP appender that emails me whenever an exception is handled by the filter.



来源:https://stackoverflow.com/questions/3397856/how-do-i-access-an-unhandled-exception-in-an-mvc-error-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!