如何让ASP.NET MVC遵守我的customErrors设置?

Cha*_*tes 5 error-handling asp.net-mvc custom-error-pages custom-errors asp.net-mvc-3

在我的web.config中的customErrors标记中,我指向一个控制器.在我的控制器中,我将重定向到由多个应用程序共享的外部错误页面.

<customErrors defaultRedirect="~/Error/ServerError" mode="On">

我的控制器:

public class ErrorController : Controller
{

    public ActionResult ServerError()
    {
        return Redirect("/Systems/ASPNETErrorHandling/ErrorPage.aspx");
    }

    public ActionResult ErrorTest()
    {
        throw new Exception("testing error handling");
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在调用Error/ErrorTest来测试错误处理.但它总是重定向到Views/Shared/Error.cshtml而不是重定向到我指定的控制器.

如何让asp.net mvc遵守customErrors设置中的defaultRedirect路径?

UDPATE:我还使用ELMAH并重写HandleErrorAttribute在描述这个职位.我从.Net Reflector看到,基础HandleErrorAttribute将Error设置为视图.我不认为我可以做很多事情,重定向到Error.cshtml,或其他一些视图.

Cha*_*tes 2

就像我在问题更新中所说的那样,我将重写本文中描述的 HandleErrorAttribute以便使用 ELMAH。基类自动将 Error 设置为视图。所以我只是注释掉base.OnException(context);并且它有效。我不知道这是否是最好的解决方案,但我认为它应该适合我的目的。