MVC的HandleError筛选器未捕捉异常 [英] MVC HandleError filter didn't catch an exception

查看:135
本文介绍了MVC的HandleError筛选器未捕捉异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中我使用MVC 3 Web应用程序的HandleError 操作过滤器。我这个动作过滤器实现如下:

  [的HandleError]
公共类BaseController:控制器{...}

这是从我的所有控制器都派生的基类。在我的web.config我已经的 的和有一个 Error.cshtml 在我的共享文件夹(.cshtml因为我用剃刀)。一切都已经好了,我得到了一个精美异常处理(我的功能格式化)

近日,不知何故,我得到了和未处理的异常(YSOD)因为的customErrors我得到了它没有对实际的异常任何信息默认ASP.Net的错误消息。这是发生在一个AJAX回发。不过,我无法重现它。

是否有可能在任何类型的错误逃离这个动作过滤器?


解决方案

  

是否有可能在任何类型的错误逃离这个动作过滤器?


的HandleError 过滤器不赶在应用程序中触发的所有异常。它可以捕捉在里面行动,行动过滤器发射..简单的MVC上下文中的例外。此外,它不会捕获 HTTP 具有比500仅的HandleError 依托其他状态code异常筛选MVC应用程序是一个坏主意。

您还是应该依靠的Application_Error 事件做一些记录和的customErrors 部分中显示自定义错误页对于不是由的HandleError 捕获的异常。

我写了一个博客帖子关于这个问题,可以帮助您

I've an MVC 3 web app in which I'm using "HandleError" Action Filter for exception handling. I've this action filter implemented as follows:

[HandleError]
public class BaseController : Controller {...}

This is the base class from which all of my controllers are derived. In my web.config I've and there's an Error.cshtml in my Shared folder (.cshtml because I use Razor). Everything has been working fine and I get a fine exception handling (formatted by my function)

Recently, somehow I got and "unhandled exception (YSOD)" and because of "customErrors" I got the default ASP.Net error message which didn't have any info about the actual exception. This happened in an AJAX post back. However, I'm unable to reproduce it.

Is it possible for any sort of errors to escape this action filter?

解决方案

Is it possible for any sort of errors to escape this action filter?

HandleError filter doesn't catch all the exceptions fired in an application. It can capture exceptions that are fired inside actions, action filters.. simply inside the MVC context. Also it doesn't capture HTTP exceptions having status code other than 500. Relying only on HandleError filter in an MVC application is a bad idea.

You should still rely on the Application_Error event to do some logging and customErrors section to display a custom error page for the exceptions that are not captured by HandleError.

I've written a blog post on this subject that may help you.

这篇关于MVC的HandleError筛选器未捕捉异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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