【发布时间】:2018-03-28 01:53:01
【问题描述】:
“/”应用程序中的服务器错误。 防伪cookie令牌和表单字段令牌不匹配。
我已经上传了我的项目。发布后它显示此错误。有时它第一次成功登录,但在第二次尝试时出现此错误。我在同一视图页面上有两个两个防伪令牌。
我的登录模式如下。
<div id="myModal" class="reveal-modal small" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h2><i class="social foundicon-torso"></i> <b>LOG <span style="color:#f47e00;">IN</span></b></h2>
<hr />
<br />
@using (Html.BeginForm("Login", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="row">
<div class="large-12 columns">
<label>
Enter Email Address
@Html.EditorFor(model => model.email, new { })
</label>
</div>
<div class="large-12 columns">
<label>
Enter Password
@Html.PasswordFor(model => model.password, new { })
</label>
</div>
<small>If you don't have a account click here to <a href="#" data-reveal-id="signup" style="color:#3b5998;;">Sign up</a></small>
</div>
<br />
<hr />
<button type="submit" class="button tiny right" style="color:white;margin-left:5px;">Login</button>
<a href="#" class="button secondary tiny right close-reveal-modal" style="position:relative; font-size: 0.6875rem;color:inherit;top:0;right:0; font-weight: 300;" aria-label="Close">Cancel</a>}
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
控制器中的登录代码如下
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(users user)
{
var v = db.users.Where(modal => modal.email.Equals(user.email)).Where(modal => modal.password.Equals(user.password)).SingleOrDefault();
if (v != null)
{
// ViewBag.Company = v;
Logout(user.email);
UserData(v.email, v.username, v.usersId, v.accountype,v.cinc,v.cell,v.dob, v.gender, v.country, v.city, v.mstatus, v.address, v.age);
return RedirectToAction("index");
}
return RedirectToAction("WrongPassword/0");
}
【问题讨论】:
-
请显示控制器的代码。
-
请检查我已发布代码。
-
页面上是否有多个@Html.AntiforgeryToken?我注意到您显示的视图代码是用于模式的,“父”页面或 _Layout.cshtml 中是否包含另一个防伪标记?当包含多个令牌时,我遇到了类似的问题。
-
使用防伪令牌进行注册和登录的价值有限。它们非常有价值一旦您登录,但在此之前价值较小。
标签: c# asp.net asp.net-mvc release