问题描述
我已经实现了一种方法,该方法通过重写从HandleErrorAttribute继承的类中的OnException函数来处理AntiForgeryTokenError。 但是,这要求我将filterContext(ExceptioContext)'ExceptionHandled设置为true。
不幸的是,这将覆盖我的webConfig的customErrors mode =“ RemoteOnly”,并且拒绝我在开发/调试环境中收到默认的YSOD stackTrace错误。 所以,.. 我要
RemoteOnly模式YSOD屏幕
和我的自定义错误页面(即Error.cshtml及其控制器+操作)
以及当用户使用浏览器的“后退”按钮返回到缓存的视图时处理过期或旧的防伪令牌的功能。
即
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) });
}
}
HandleAntiForgeryTokenErrorAttribute:FilterContext.ExceptionHandled属性设置为true。
public class HandleAntiForgeryTokenErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
filterContext.ExceptionHandled = true;
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(new { action = "Index",controller = "Error" }));
}
}
是否有一种方法可以确保满足所有三个条件? 非常感谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)