我上传了我的项目。发布后显示此错误。有时它第一次成功登录,但在第二次尝试时它会出现此错误。我在同一个视图页面上有两个防伪标记。
我的登录模式如下。
<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");
}
答案 0 :(得分:0)
我通过在web.config中明确添加机器密钥解决了这个问题。
注意:出于安全原因,请勿使用此密钥。从https://support.microsoft.com/en-us/kb/2915218#AppendixA生成一个。不要使用在线一,详情,http://blogs.msdn.com/b/webdev/archive/2014/05/07/asp-net-4-5-2-and-enableviewstatemac.aspx
<machineKey validationKey="971E32D270A381E2B5954ECB4762CE401D0DF1608CAC303D527FA3DB5D70FA77667B8CF3153CE1F17C3FAF7839733A77E44000B3D8229E6E58D0C954AC2E796B" decryptionKey="1D5375942DA2B2C949798F272D3026421DDBD231757CA12C794E68E9F8CECA71" validation="SHA1" decryption="AES" />
这是一个生成唯一机器密钥的网站: