In my application sometimes i get the exception when I try to log in:
A required anti-forgery token was not supplied or was invalid.
I can't reproduce it in 100%, but it happens frequently.
My guess is that is has something to do with multiple login forms on the same page.
More precisely:
On top of my page there is a small log in/out panel always visible.
If the unauthorized user tries an action he's not supposed to, he gets redirected to a dedicated log in page.
- Than there are 2 different forms pointing to the same action.
Both forms have:
@Html.AntiForgeryToken()
The log in action is decorated with:
[ValidateAntiForgeryToken]
My questions:
- Can this be the problem?
- If not, than what can it be?
- And of course how to fix it?
Please note that:
- This top log in/out panel is in a partial, which is in a partial ... which is in the _Layout.cshtml
- The dedicated log in page is rendered as a body.