ValidateAntiForgeryToken with SPA architecture

后端 未结 4 1424
南旧
南旧 2020-12-24 04:07

I am trying to set Register and Login for Hot Towel SPA applicantion. I have created SimpleMembershipFilters and ValidateHttpAntiForgeryTokenAttribute based on the asp.net s

4条回答
  •  臣服心动
    2020-12-24 04:31

    Grab value of token in JS var

    var antiForgeryToken = $('input[name="__RequestVerificationToken"]').val();
    

    Then just add to your ajax POST headers in the beforeSend function of the .ajax call

    beforeSend: function (xhr, settings) {
                if (settings.data != "") {
                    settings.data += '&';
                }
                settings.data += '__RequestVerificationToken=' +  encodeURIComponent(antiForgeryToken);
    }
    

提交回复
热议问题