开发者

Using ValidateAntiForgeryToken with Ajax.ActionLink

开发者 https://www.devze.com 2022-12-12 02:25 出处:网络
Is it possible to use the ValidateAntiForgeryToken attribute on a controller action when the request comes from Ajax.ActionLink (using Http Method Post?). The alternative appear开发者_StackOverflow中文

Is it possible to use the ValidateAntiForgeryToken attribute on a controller action when the request comes from Ajax.ActionLink (using Http Method Post?). The alternative appear开发者_StackOverflow中文版s to be to hand roll a JQuery Ajax request but I am curious if there is a way within the MVC Ajax framework.


I haven't seen a baked-in way. You have to get the token into the data that goes up in the POST. The antiforgery token's ID (or name, I can't remember) is the same each time, but you have to be real careful, and make sure that the anti forget token you are using is the most recent one rendered to the client, which can get tricky in an AJAX app.

0

精彩评论

暂无评论...
验证码 换一张
取 消