MVC 4提供的防伪标记是为那些用户QUOT;"但是当前用户是"用户QUOT; [英] MVC 4 provided anti-forgery token was meant for user "" but the current user is "user"

查看:370
本文介绍了MVC 4提供的防伪标记是为那些用户QUOT;"但是当前用户是"用户QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近把直播,其使用的 MVC 4 实体框架5 内置的Web应用程序。在 MVC 应用程序使用的剃须刀浏览

I've recently put Live a web application which was built using MVC 4 and Entity Framework 5. The MVC application uses Razor Views.

我发现使用的 ELMAH ,当用户登录到应用程序中,有时他们得到以下错误

I noticed using Elmah that when users are logging into the application, sometimes they are getting the following error

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
      }

}

我觉得这一切看起来正常,但仍是错误仍然存​​在。是否任何有关于如何解决这个问题的任何想法?

I thought this all looked OK, but still the error persists. Does any have any ideas on how to fix this problem?

您帮助是极大的AP preciated。

Your help is greatly appreciated.

感谢。

推荐答案

我认为这正在发生,因为用户双击提交表单按钮。至少这正是在我的网站的情况。

I believe this is occurring because the users are double-clicking the submit button on the form. At least that's EXACTLY the case on my site.

<一个href=\"http://stackoverflow.com/questions/5767768/troubleshooting-anti-forgery-token-problems\">Troubleshooting防伪标记问题

这篇关于MVC 4提供的防伪标记是为那些用户QUOT;&QUOT;但是当前用户是&QUOT;用户QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆