Why does .net core Blazor HttpClient.PostAsJsonAsync get a 400 bad request with ValidateAntiForgeryRequestToken

Viewed 41

I am working on a Blazor Server project, and I am doing a POST using HttpClient.PostAsJsonAsync in a Razor page. The anti forgery request token seems to have some difficulties. When I put the directive [ValidateAntiForgeryToken] with the Post action, it fails with a 400 Bad Request. I’m getting a 200 Success when the directive is not present.

This is not consistent with the documentation I’ve read on .net core. See the following URL

It contains the following statement:

Razor Pages are automatically protected from XSRF/CSRF. For more information, see XSRF/CSRF and Razor Pages.

Why is the post failing with [ValidateAntiForgeryToken]? I appreciate any words of wisdom on this.

0 Answers
Related