asp.net mvc - The "Back" button and the anti-forgery token -
asp.net mvc - The "Back" button and the anti-forgery token -
i'm getting runtime error
related the anti-forgery attribute.
perform next steps:
create mvc web application , start register joe@acme.org sign out register jane@acme.org sign out login joe@acme.org hit button login jane@acme.orgerror: the provided anti-forgery token meant different claims-based user current user.
what can done prevent error occurring?
this 1 way of ignoring error , returning user login screen. it's example.
create new class called handleantiforgerytokenerrorattribute
inherits handleerrorattribute
. override onexception
method.
public class handleantiforgerytokenerrorattribute : handleerrorattribute { public override void onexception(exceptioncontext filtercontext) { filtercontext.exceptionhandled = true; filtercontext.result = new redirecttorouteresult( new routevaluedictionary(new { action = "login", controller = "account" })); } }
go filterconfig
class , register attribute global filter.
public class filterconfig { public static void registerglobalfilters(globalfiltercollection filters) { filters.add(new handleerrorattribute()); filters.add(new handleantiforgerytokenerrorattribute() { exceptiontype = typeof(httpantiforgeryexception) } ); } }
asp.net-mvc razor
Comments
Post a Comment