Relative Content

Tag Archive for ajaxasp.net-core-mvcantiforgerytoken

Correct way to send AntiForgeryToken through AJAX request

I’ve been trying to send the AntiForgeryToken through AJAX request in an ASP.NET Core MVC (area based) Razor view; however, I am definitely missing something to send in the POST request. I read through several documentations and StackO. answers, but all of them are missing something common that I found on this MS documentation: Preventing Cross-Site Request Forgery (CSRF) Attacks in ASP.NET MVC Application. I looked at this StackO. question and the replies, and the common difference is that the MS documentation sends both the cookie and form (hidden element) token but I get an error message saying AntiForgery.GetTokens(null, out cookieToken, out formToken) does not exist in the current context.