How do I get ASP.NET MVC to honor my customErrors settings?

回眸只為那壹抹淺笑 提交于 2019-12-05 00:17:40

问题


In the customErrors tag in my web.config, I am pointing to a controller. In my controller I am redirecting to an external error page that is shared by multiple applications.

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

My controller:

public class ErrorController : Controller
{

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

    public ActionResult ErrorTest()
    {
        throw new Exception("testing error handling");
    }
}

I'm calling Error/ErrorTest to test the error handling. But it always redirects to Views/Shared/Error.cshtml instead of redirecting to the controller I specified.

How do I get asp.net mvc to honor the defaultRedirect path in my customErrors settings?

UDPATE: I'm also using ELMAH and overriding the HandleErrorAttribute as described in this post. I see from .Net Reflector that the base HandleErrorAttribute is setting Error as the view. I don't think there's much I can do about it redirecting to Error.cshtml, or some other view.


回答1:


Like I said in the update to my question, I'm overriding the HandleErrorAttribute as described in this post in order to use ELMAH. The base class automatically sets Error as the view. So I just commented out base.OnException(context); and it works. I don't know if it's the best solution, but I think it should work for my purposes.



来源:https://stackoverflow.com/questions/5706155/how-do-i-get-asp-net-mvc-to-honor-my-customerrors-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!