使用ValidateAntiForgeryToken与Ajax.ActionLink [英] Using ValidateAntiForgeryToken with Ajax.ActionLink

查看:202
本文介绍了使用ValidateAntiForgeryToken与Ajax.ActionLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用控制器上的动作ValidateAntiForgeryToken属性,当请求来自Ajax.ActionLink(使用HTTP POST方法?)。另一种方法似乎是手卷一个jQuery Ajax请求,但我很好奇,如果有是MVC的Ajax框架内的一种方式。

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 appears to be to hand roll a JQuery Ajax request but I am curious if there is a way within the MVC Ajax framework.

推荐答案

我还没有看到一个烤的方式。你必须得到令牌成上升的POST数据。该防伪标记的ID(或名称,我不记得)是一样的每一次,但你必须是真实的谨慎,并确保防忘记你正在使用的是最近的一次呈现给客户端,令牌,该令牌可以在AJAX应用程序变得棘手。

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.

这篇关于使用ValidateAntiForgeryToken与Ajax.ActionLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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