asp.net-mvc – MVC 4提供的反伪造令牌是为用户“”而是当前用户是“用户”

我最近把Live MVC 4和Entity Framework 5构建了一个Web应用程序.MVC应用程序使用Razor Views.

我注意到使用Elmah,当用户登录应用程序时,有时他们会收到以下错误

The provided anti-forgery token was meant for user "" but the current user is "user"

我已经做了一些关于如何解决这个问题的研究,但对我来说似乎没有任何效果.请参阅我的登录视图和相应的控制器操作.

剃刀视图

@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
      }

}

我以为这一切都看起来不错,但仍然存在错误.有没有任何想法如何解决这个问题?

您的帮助非常感谢.

谢谢.

解决方法

我相信这是因为用户双击表单上的提交按钮而发生.至少在我的网站上是这样的.

Troubleshooting anti-forgery token problems

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....