jQuery Ajax calls and the Html.AntiForgeryToken()

前端 未结 20 2535
鱼传尺愫
鱼传尺愫 2020-11-22 16:34

I have implemented in my app the mitigation to CSRF attacks following the informations that I have read on some blog post around the internet. In particular these post have

20条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 17:23

    You can do this also:

    $("a.markAsDone").click(function (event) {
        event.preventDefault();
    
        $.ajax({
            type: "post",
            dataType: "html",
            url: $(this).attr("rel"),
            data: $('
    @Html.AntiForgeryToken()
    ').serialize(), success: function (response) { // .... } }); });

    This is using Razor, but if you're using WebForms syntax you can just as well use <%= %> tags

提交回复
热议问题