How can I execute a controller action in ASP.NET MVC4 sending the anti foreign key too?
My request is formed as follow code snippet:
var _antiForeignKey = dojoQuery('input[name="__RequestVerificationToken"]', dojo.byId('#__AjaxAntiForgeryForm'))[0].value;
xhr.post({
url: 'Account/LogOff',
handleAs: 'json',
contentType: 'application/json',
postData: '__RequestVerificationToken=' + _antiForeignKey
});
And I receive an error from server with a html which contains the
The required anti-forgery form field "__RequestVerificationToken" is not present.
message as response. Obviously, the action in the controller is not executed.
I've seen this post: jQuery Ajax calls and the Html.AntiForgeryToken(), which answers my question but using jQuery.