Instead of checking User.Identity.IsAuthenticated, like some of the other posts mentioned, I used my own attribute to handle exceptions and redirect the user to the home page if it is an HttpAntiForgeryToken
I believe that this avoids any potential security issues when using other methods, and that [ValidateAntiForgeryToken] should always be used in POST methods
public override void OnException(ExceptionContext filterContext) { var controllerName = (string)filterContext.RouteData.Values["controller"]; var actionName = (string)filterContext.RouteData.Values["action"]; var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName); if (filterContext.Exception is HttpAntiForgeryException) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "action", "Index" }, { "controller", "Home" } }); filterContext.ExceptionHandled = true; } }
bla9x Apr 29 '19 at 21:57 2019-04-29 21:57
source share