无法解密防伪令牌 [英] The anti-forgery token could not be decrypted

查看:104
本文介绍了无法解密防伪令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格:

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary()...

和动作:

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl, string City)
{
}

偶尔(每周一次),我收到错误:

occasionally (once a week), I get the error:

无法解密防伪令牌.如果这个应用程序是由 Web Farm 或集群托管,确保所有机器都在运行相同版本的 ASP.NET 网页和配置指定显式加密和验证密钥.自动生成不能在集群中使用.

The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the configuration specifies explicit encryption and validation keys. AutoGenerate cannot be used in a cluster.

我尝试添加到 webconfig:

i try add to webconfig:

<machineKey validationKey="AutoGenerate,IsolateApps"  
    decryptionKey="AutoGenerate,IsolateApps" />

但是偶尔还是会出现这个错误

but the error still appears occasionally

我注意到这个错误发生,例如当一个人来自一台计算机然后尝试另一台计算机时

I noticed this error occurs, for example when a person came from one computer and then trying another computer

或者有时使用不正确的数据类型(例如 bool 到 integer)设置自动值到表单字段,通过任何 jQuery 代码也请检查它.

Or sometimes an auto value set with incorrect data type like bool to integer to the form field by any jQuery code please also check it.

推荐答案

我也刚收到这个错误,就我而言,这是由于防伪令牌以相同的形式应用了两次造成的.第二个实例来自局部视图,因此不是很明显.

I just received this error as well and, in my case, it was caused by the anti-forgery token being applied twice in the same form. The second instance was coming from a partial view so wasn't immediately obvious.

这篇关于无法解密防伪令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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