Error handling 处理被重写的MVC5 OneException,但仍使用customErrors模式提供AntiForgeryTokenError=";RemoteOnly“;
我已经实现了一种方法来处理AntiForgeryTokenError,方法是在继承自HandleErrorAttribute的类中重写OneException函数。 但是,这需要将filterContext(ExceptionContext)'ExceptionHandled设置为true 不幸的是,这会覆盖我的webConfig的customErrors mode=“RemoteOnly”,并拒绝我在开发/调试环境中获得默认的YSOD stackTrace错误。 所以 我要 RemoteOnly模式YSOD屏幕 和我的自定义错误页面(即error.cshtml及其控制器+操作) 当用户使用浏览器的“后退”按钮返回缓存视图时,能够处理过期或旧的反伪造令牌 i、 e 是否有办法确保满足所有3个标准? 非常感谢Error handling 处理被重写的MVC5 OneException,但仍使用customErrors模式提供AntiForgeryTokenError=";RemoteOnly“;,error-handling,asp.net-mvc-5,antiforgerytoken,Error Handling,Asp.net Mvc 5,Antiforgerytoken,我已经实现了一种方法来处理AntiForgeryTokenError,方法是在继承自HandleErrorAttribute的类中重写OneException函数。 但是,这需要将filterContext(ExceptionContext)'ExceptionHandled设置为true 不幸的是,这会覆盖我的webConfig的customErrors mode=“RemoteOnly”,并拒绝我在开发/调试环境中获得默认的YSOD stackTrace错误。 所以 我要 RemoteOnl
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
// The default implementation of the IExceptionFilter, which handles exceptions only if the <customErrors> is turned on in web.config
filters.Add(new HandleErrorAttribute());
filters.Add(new HandleAntiForgeryTokenErrorAttribute()
{ ExceptionType = typeof(HttpAntiForgeryException) });
}
}
public class HandleAntiForgeryTokenErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
filterContext.ExceptionHandled = true;
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(new { action = "Index", controller = "Error" }));
}
}