Search code examples
c#asp.net-core.net-coreasp.net-core-webapiantiforgerytoken

.Net Core ValidateAntiForgeryToken throwing web api 400 error


Visual Studio 2017 with Web Api using .net Core 1.1 I'm using, but I am getting a 400 Bad Request Error.

Error Occurs in every way:

  1. Angular http
  2. Fiddler
  3. Postman
  4. SoapUI
  5. Swagger

ASP.NET Web API “400 Bad Request” on POST Request

[HttpPut]
//[ValidateAntiForgeryToken]
public IActionResult Put([FromBody]VeteranInteraction sessionTracker)
{ //.... } 

Why is this happening ?

ValidateAntiForgeryToken is the problem , if I comment it out it works.


Solution

  • You need to send the AntiForgery token on every request where it's being validated either as a cookie or as a http header.

    Refer to the documentation here. They have a section on how to configure angular js to do it.