I saw many people had this problem for different reasons and until now I could not find any solution but remove the AntiForgeryToken.
My app is structured like this:
Login form (Allow cnnonymous, uses a single AntiForgeryToken)
Data manipulation page (Only authenticated users, several AntiForgeryTokens, one for each modal window and their
<form>
tags)
If I open the application and log in with the user A, I can insert information using the data manipulation page correctly. However, if I just go to this data manipulation page, log out of the current user (A), log in with the user B and go to the data manipulation page again, I receive the error "The provided anti-forgery token was meant for user 'PREVIOUS', but the current user is 'CURRENT'" when I click the submit button.
I'm using only the form button to submit, without AJAX. This application is running on ASP.Net MVC 4, using FormsAuthentication and using the following code to log out users:
HttpContext.Session.Clear();
FormsAuthentication.SignOut();
What do I have to do to fix it? It's been 6h and many things tried out, but no success.
PS: I did a previous search on StackOverflow and:
- no, I'm not using Ajax to log in or to insert the data
- I don't have more than one AntiForgeryToken on any form, but I do have pages with more than one form (each with their own AntiForgeryToken)