In a MVC4 app running on Mono I get the error:
The anti-forgery cookie token and form field token do not match
on the "Login and Register" page. This page has a LoginOrRegisterViewModel
which looks as follows:
public class LoginOrRegisterViewModel
{
public LoginModel Login { get; set; }
public RegisterModel Register { get; set; }
}
Which gets passed to the page on the GET request.
There are two Html.BeginForms()
on the page, a Login
-form and a Register
-form. The first calls the Login
action on the controller, the second the Register
action. Both actions have a ValidateAntiForgeryToken
attribute. When a form is submitted the respectively Login
or Register
is obtained from the LoginOrRegisterViewModel
.
When the page is loaded and a registered user tries to login after some tim (few hours?) the "Login and Register" page initially shows, but when the Login
form is submitted the error above shows until the root page is refreshed.
I have included a Machine Key to the Web.config and have added Html.AntiForgeryToken()
to both forms. I have a suspicion this error might have to do with the two forms and the view model.
Does anyone know how the error can be fixed? Thanks.