I'm having this errors. I have a windows server. I directed server's ıp address to https://api.example.com When I try api it works like https://api.example.com/api/test it return datas
I having an error is not equal to when my code like this:
builder.Services.AddCors(options => options.AddDefaultPolicy(
policy => policy
.WithOrigins("https://www.example.com.tr")
.AllowAnyHeader()
.AllowAnyMethod()
));
app.UseCors();
Access to XMLHttpRequest at 'https://api.example.com/api/test' from origin 'https://example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'http://www.example.com' that is not equal to the supplied origin.
if I change the origin like https://example.com.tr I'm having multiple values error.
builder.Services.AddCors(options => options.AddDefaultPolicy(
policy => policy
.WithOrigins("https://example.com.tr")
.AllowAnyHeader()
.AllowAnyMethod()
));
app.UseCors();
Access to XMLHttpRequest at 'https://api.example.com/api/test' from origin 'https://example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'http://www.example.com' that is not equal to the supplied origin.
I added this lines to my web api's web confing file
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Headers" value="*" />
<add name="Access-Control-Allow-Methods" value="*" />
</customHeaders>
</httpProtocol>