Hello,
We'd been getting "A required anti-forgery token was not supplied or was invalid." errors, and on some further investigation, I've managed to recreate the problem in its simplest form - i'm either doing something completely wrong, or this is a limitation of the anti-forgery token system.
Either way, I'd appreciate some advice!
Empty MVC 2 project: one view page, one controller
view:
<%--Sign in form:--%>
<% using(Html.BeginForm("SignIn", "Home", FormMethod.Post)) {%>
<%= Html.AntiForgeryToken()%>
<input type="submit" value="Sign in" />
<%}%>
Controller:
public ActionResult Index()
{
ViewData["status"] = "Index";
return View();
}
[ValidateAntiForgeryToken]
public ActionResult SignIn()
{
ViewData["status"] = "Signed In!";
FormsAuthentication.SetAuthCookie("username", false);
return View("Index");
}
[EDIT: simplified code example]
In order to recreate the exception, open two non-signed-in tabs - sign-in on the first tab, and then sign-in on the second tab.
The second tab will always throw an anti-forgery exception, when I guess correct behaviour would be to redirect to the signed-in page (sharing the session/authentication of the original signed-in tab)
Any advice would be appreciated!
Cheers, Dave