我最近发布了一个使用MVC 4和Entity Framework 5构建的Web应用程序。这个MVC应用程序使用Razor Views。
我注意到使用Elmah时,当用户登录应用程序时,有时会出现以下错误。
我注意到使用Elmah时,当用户登录应用程序时,有时会出现以下错误。
The provided anti-forgery token was meant for user "" but the current user is "user"
我已经进行了一些研究,试图解决这个问题,但似乎没有什么对我起作用的。请查看下面的登录视图和相应的控制器操作。
Razor视图
@if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="formEl_a">
<fieldset>
<legend>Login Information</legend>
<div class="lbl_a">
Email
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Email, new { @class = "inpt_a" })<br />
@Html.ValidationMessageFor(m => m.Email)
</div>
<div class="lbl_a">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field sepH_b">
@Html.PasswordFor(m => m.Password, new { @class = "inpt_a" })<br />
@Html.ValidationMessageFor(m => m.Password)
</div>
</fieldset>
</div>
<br />
<p>
<input type="submit" value="Log In" class="btn btn_d sepV_a" />
</p>
}
}
控制器
[AllowAnonymous]
public ActionResult Login()
{
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && _accountService.Logon(model.Email, model.Password, true))
{
//Validate
}
else
{
// inform of failed login
}
}
我认为这一切看起来都没问题,但错误仍然存在。有没有人对如何解决这个问题有任何想法?
非常感谢您的帮助。
谢谢。