如何在一个MVC错误视图访问未处理的异常? [英] How do I access an unhandled exception in an MVC Error view?

查看:111
本文介绍了如何在一个MVC错误视图访问未处理的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个控制器上的的HandleError 属性检测未处理的异常,并重定向到错误的看法,我想为用户提供了错误的简短描述,一个选项,错误电子邮件应用程序管理员。

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.

我有一个自定义的的HandleError ,通知ELMAH记录错误,但是你不得不去查找错误的ELMAH日志似乎有点不得已而为之的。是否有任何其他方式来访问由的HandleError

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?

推荐答案

HandleErrorAttribute 耗材类型的Model对象 HandleErrorInfo
您的错误页面可能看起来像这样

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

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

该模型有一个例外与异常的细节处理财产

我通常使用一个自定义的错误处理程序也使用记录异常 log4net的和我有一个STMP追加程序的电子邮件,我只要一个异常被过滤处理。

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.

这篇关于如何在一个MVC错误视图访问未处理的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆