我有一个包含两个部分 View A 和 B 的 MVC 页面。当我提交部分 View B 时,仅在第一次出现此错误。
The anti-forgery cookie token and form field token do not match.
第一次之后, View 效果完美。我已在代码页中添加了 [ValidateAntiForgeryToken]
,并在部分 View 中添加了 @Html.AntiForgeryToken()
。
当我从页面中删除部分 View A 时,B 正在正常工作,没有任何错误。
任何建议都会很有帮助。
最佳答案
当您具有[ValidateAntiForgeryToken]
属性时,框架会执行以下操作
- 检查传入请求是否具有名为
__RequestVerificationToken
的 Cookie - 检查传入请求是否具有名为
__RequestVerificationToken
的Request.Form
条目 - 检查 cookie 和
Request.Form
值是否匹配
由于上述过程,一个页面只能有一个有效的 AntiForgery token 。
关于asp.net-mvc - MVC antiforgerytoken 部分 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26166236/