提供的防伪令牌适用于用户"",但当前用户为"xxxx".
我已经按照每一个解决方案来摆脱这个错误而没有任何成功:
这是场景:我在浏览器选项卡中打开了2个单独的登录选项卡A选项卡B:1.我在选项卡A中登录我的站点2.然后尝试登录选项卡B
然后发生上述错误
我的C#web MVC登录视图有:
v class="col-md-4 col-md-offset-4">
<form class="form-signin" role="form" action=@Url.Action("Login", "Account") method="POST" id="signInForm">
@Html.AntiForgeryToken()
<div class="form-group">
<label for="loginEmail">Email</label>
<input type="text" id="loginEmail" name="loginEmail" class="form-control" placeholder="Email address" >
</div>
<div class="form-group">
<label for="loginPassword">Password</label>
<input id="loginPassword" type="password" name="loginPassword" class="form-control" placeholder="Password" >
</div>
<button class="btn btn-lg btn-primary btn-block main-btn" type="submit">Sign in</button>
<div>
<br>
<a href="@Url.Action("Index","GettingStarted")">Register</a><br>
<a href="@Url.Action("ForgotPassword","Account")">Forgot your password?</a>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我的帐户控制器是这样的:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model)
{
if (ModelState.IsValid)
{
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
Sam*_*lgh 14
发生这种情况是因为两个浏览器选项卡共享同一个cookie存储.使用第一个标签进行身份验证会设置一个标识用户名的新Cookie.提交第二个选项卡时,它将传递从第一个选项卡中成功验证中检索到的更新cookie,以及在验证之前加载的隐藏表单字段,该字段将您标识为匿名用户.因为cookie中的用户名和隐藏的表单字段不匹配,验证失败.
ValidateAntiForgeryTokenAttribute使用的AntiForgeryWorker将经过身份验证的用户名编码到Cookie和隐藏的表单字段中,并确保它们在验证时都匹配.因此,每当您进行身份验证或更改用户时,如果使用ValidateAntiForgeryTokenAttribute发布到操作,则此验证将失败.
不幸的是,这意味着您的选项仅限于不使用ValidateAntiForgeryTokenAttribute保护登录操作,忽略您描述的方案并让验证失败,或者重新实现MVC中的AntiForgery实现,这样在验证过程中不包含用户名.
归档时间: |
|
查看次数: |
11023 次 |
最近记录: |