环球错误ASP.NET MVC处理(外控制器) [英] Global error handling (outside of controller) in ASP.NET MVC

查看:107
本文介绍了环球错误ASP.NET MVC处理(外控制器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我把下面的code某处母版页在我的ASP.NET MVC网站:

Let's say I put the following code somewhere in a Master page in my ASP.NET MVC site:

throw new ApplicationException("TEST");

即使把我的控制器上的[的HandleError]属性,这个异常仍冒泡。我该如何处理这样的错误?我希望能够路由到了错误的网页,仍然可以登录异常的详细信息。

Even with a [HandleError] attribute placed on my controller, this exception still bubbles up. How can I deal with errors like this? I would like to be able to route to an Error page and still be able to log the exception details.

什么是对付像这样的最佳方式?

What is the best way to deal with something like this?

编辑:一种解决方案我正在考虑将添加一个新的控制器:UnhandledErrorController。我可以把在Global.asax中的Application_Error事件,然后重定向到该控制器(它决定如何处理异常做)?

One solution I was considering would be to add a a new controller: UnhandledErrorController. Can I put in an Application_Error method in Global.asax and then redirect to this controller (where it decides what to do with the exception)?

注:的defaultRedirect在web.config中的customErrors元素不沿异常信息传递。

Note: the defaultRedirect in the customErrors web.config element does not pass along the exception info.

推荐答案

由于MVC是建立在asp.net的顶部,你应该能够在的 web.config中,就像你可以在Web表单如:

As MVC is built on top of asp.net you should be able to define a global error page in web.config, just like you could in web forms eg.

   <customErrors mode="On" defaultRedirect="~/ErrorHandler" />

这篇关于环球错误ASP.NET MVC处理(外控制器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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