我正在使用ASP.NET MVC 4中的默认登录模块。我没有改变默认应用程序中的任何代码,并将其托管在共享服务器上。
在使用默认登录页面登录后,当我让浏览器闲置一段时间后,当我尝试执行任何带有[Authorize]
属性的控制器操作时,应用程序显然会重定向到登录页面。
然后我尝试重新登录,但当我单击登录按钮时,它会出现错误。
The anti-forgery cookie token and form field token do not match.
登录操作
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
AntiForgeryToken
为访问者提供名为__RequestVerificationToken
的Cookie,并将其放置在页面上的隐藏字段中。当您调用服务器时,它会比较您在Cookie中拥有的值和与表单一起发送的任何内容。 - Artless