本文介绍了在 ajax post ASP.NET MVC 中包含 antiforgerytoken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 ajax 时遇到了 AntiForgeryToken 的问题.我正在使用 ASP.NET MVC 3.我在 jQuery Ajax 调用中尝试了解决方案和 Html.AntiForgeryToken().使用该解决方案,现在正在传递令牌:
var data = { ... }//带令牌,key 是 '__RequestVerificationToken'$.ajax({类型:POST",数据:数据,数据类型:json",传统:真实,contentType: "application/json; charset=utf-8",网址:我的网址,成功:功能(响应){...},错误:函数(响应){...}});当我删除 [ValidateAntiForgeryToken] 属性只是为了查看数据(带有令牌)是否作为参数传递给控制器时,我可以看到它们正在传递.但是由于某种原因,A required anti-forgery token 未提供或无效. 当我放回属性时仍然弹出消息.
有什么想法吗?
编辑
antiforgerytoken 是在表单内生成的,但我没有使用提交操作来提交它.相反,我只是使用 jquery 获取令牌的值,然后尝试通过 ajax 发布该值.
这是包含令牌的表单,位于顶部母版页:
更多推荐
在 ajax post ASP.NET MVC 中包含 antiforgerytoken
发布评论