加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 22:53:43 所属栏目:asp.Net 来源:网络整理
导读:我最近把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" 我已
我最近把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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读