问题描述
在我的web.config中的customErrors标签中,我指向一个控制器。在我的控制器中,我正在重定向到由多个应用程序共享的外部错误页面。
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>
我的控制器:
public class ErrorController : Controller
{
public ActionResult ServerError()
{
return Redirect("/Systems/ASPNETErrorHandling/ErrorPage.aspx");
}
public ActionResult ErrorTest()
{
throw new Exception("testing error handling");
}
}
我正在调用Error / ErrorTest来测试错误处理。但是它总是重定向到Views / Shared / Error.cshtml,而不是重定向到我指定的控制器。
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.
如何让asp.net mvc在我的customErrors设置中遵守defaultRedirect路径?
How do I get asp.net mvc to honor the defaultRedirect path in my customErrors settings?
UDPATE:我还使用ELMAH并覆盖HandleErrorAttribute,如。我从.Net Reflector看到,基础HandleErrorAttribute正在设置Error作为视图。我不认为我可以做的重定向到Error.cshtml或其他一些视图。
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.
推荐答案
像我在问题更新中说的那样,我覆盖了HandleErrorAttribute,如,以便使用ELMAH。基类自动将错误设置为视图。所以我刚刚评论了 base.OnException(context);
,它的工作原理。我不知道这是否是最好的解决方案,但我认为它应该适用于我的目的。
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.
这篇关于如何让ASP.NET MVC遵守我的customErrors设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!