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.
在我的web.config中的customErrors标记中,我指向一个控制器。在我的控制器中,我将重定向到由多个应用程序共享的外部错误页面。
<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.
我正在调用Error / ErrorTest来测试错误处理。但它总是重定向到Views / Shared / Error.cshtml而不是重定向到我指定的控制器。
How do I get asp.net mvc to honor the defaultRedirect path in my customErrors settings?
如何让asp.net mvc遵守customErrors设置中的defaultRedirect路径?
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.
UDPATE:我也在使用ELMAH并覆盖HandleErrorAttribute,如本文所述。我从.Net Reflector看到,基础HandleErrorAttribute将Error设置为视图。我不认为我可以做很多事情,重定向到Error.cshtml或其他一些视图。
1 个解决方案
#1
2
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.
就像我在我的问题的更新中所说的那样,我正在重写HandleErrorAttribute,如本文所述,以便使用ELMAH。基类自动将Error设置为视图。所以我只是注释掉了base.OnException(context);它的工作原理。我不知道这是否是最佳解决方案,但我认为它应该适用于我的目的。
#1
2
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.
就像我在我的问题的更新中所说的那样,我正在重写HandleErrorAttribute,如本文所述,以便使用ELMAH。基类自动将Error设置为视图。所以我只是注释掉了base.OnException(context);它的工作原理。我不知道这是否是最佳解决方案,但我认为它应该适用于我的目的。