Sharif Mamun
Sharif Mamun

Reputation: 3574

AntiforgeryValidationException: The required antiforgery header value "RequestVerificationToken" is not present

I am trying to authorize a cloud provider following this on localhost, in ConfigureServices method, my Startup.cs file has

services.AddAntiforgery(options => options.HeaderName = "RequestVerificationToken");

Inside a [HttpGet] controller method, I am trying to validate the request with:

await _antiforgery.ValidateRequestAsync(HttpContext);

This is throwing the exception. Can anyone please suggest what I am doing wrong here?

Thanks!

Upvotes: 3

Views: 3028

Answers (1)

Ivan R.
Ivan R.

Reputation: 1915

GET method should not change any data, so it is considered as a safe method and there is no need to protect this method from CSFR. You can see from the example, only POST method is protected. Your browser sends GET request to your site without additional anti forgery header, that is why the exception is thrown.

Upvotes: 5

Related Questions