MVC3异常处理和customErrors问题

时间:2011-06-21 14:23:17

标签: asp.net-mvc-3 error-handling custom-error-pages

我正在尝试MVC3异常处理,并附带以下测试代码:

public class HomeController : Controller {
    public ActionResult Index() {
        throw new ArgumentException();
        return View();
    }
}

我的控制器强制抛出异常,并在我的web.config

<customErrors mode="On" defaultRedirect="~/ErrorHandler/Index">
  <error statusCode="404" redirect="~/ErrorHandler/NotFound"></error>
</customErrors>

我已经为服务器ErrorHandler / Index和ErrorHandler / NotFound请求创建了另一个控制器。

通过我的测试,我可以看到可以捕获404代码,但完全忽略了500个代码。

我的代码有什么问题吗?

由于 哈迪

1 个答案:

答案 0 :(得分:3)

删除以下行:

filters.Add(new HandleErrorAttribute());

来自RegisterGlobalFilters中的Global.asax方法。