c# - "The anti-forgery cookie token and form field token do not match" on page with ViewModel and two forms -
c# - "The anti-forgery cookie token and form field token do not match" on page with ViewModel and two forms -
in mvc4 app running on mono error:
the anti-forgery cookie token , form field token not match
on "login , register" page. page has loginorregisterviewmodel
looks follows:
public class loginorregisterviewmodel { public loginmodel login { get; set; } public registermodel register { get; set; } }
which gets passed page on request.
there 2 html.beginforms()
on page, login
-form , register
-form. first calls login
action on controller, sec register
action. both actions have validateantiforgerytoken
attribute. when form submitted respectively login
or register
obtained loginorregisterviewmodel
.
when page loaded , registered user tries login after tim (few hours?) "login , register" page shows, when login
form submitted error above shows until root page refreshed.
i have included machine key web.config , have added html.antiforgerytoken()
both forms. have suspicion error might have 2 forms , view model.
does know how error can fixed? thanks.
mvc best coding standard, practice separation of code concern.
create 2 diffrent model 1 loginviewmodel , 2 register view model. create seperate partial view both login , register , access via partial or renderaction keyword.if putting @html.antiforgerytoken() on html form then, same way need validate anti-forgery on controller side method writing attribute [validateantiforgerytoken()] .
html helper generate unique token within form like,
<input name="__requestverificationtoken" type="hidden" value="4dvpvqivpxnekzyv1dcjen1rmtmdj9fq2">
for each of form unique anti-forgery token generate and, resolve confliction.
let me know in case still facing difficulty.
c# asp.net-mvc-4 mono antiforgerytoken
Comments
Post a Comment