10

I have implemented Cors policy in dot net core application: In Startup.cs under ConfigureServices I have added the following cors policy

services.AddCors(options =>{
                options.AddPolicy("CorsPolicy",
                    builder => builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials());
            });

I'm facing a strange issue after adding CORS policy, on every POST call from UI there are two calls made: first calls returns with 204 and other call returns the data with 200 status code.

two calls on post request

Set
  • 40,147
  • 18
  • 114
  • 133
Nikitesh
  • 1,239
  • 1
  • 16
  • 34

1 Answers1

21

First one is a preflighted request. The main goal is to determinate whether the actual request is safe to send. Cross-site requests are preflighted since they may have implications to user data.

A CORS preflight request is a CORS request that checks to see if the CORS protocol is understood.

It is an OPTIONS request using two HTTP request headers: Access-Control-Request-Method and Access-Control-Request-Headers, and the Origin header.

A preflight request is automatically issued by a browser when needed.

This HTTP access control (CORS) describe conditions that if true then request is preflighted.

Community
  • 1
  • 1
Set
  • 40,147
  • 18
  • 114
  • 133