I have a cors implementation on a ASP netcore 3.1 MVC API. It works in Development.
In startup.cs (I basicall accept any origin in an atempt to get this working)
app.UseCors(builder=>{
builder.SetIsOriginAllowed(origin={
var host=new Uri(origin).Host;
return true; ///Accept any
})
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
})
I have a standard set of Controllers One is the User that allows Anonymous for authentication.
When I run on IISEXPRESS all works
When I run on IIS on a production like environment I get a series of errors starting with No Headers for Allow-Control-Allow-Origin
I try to set up web.config to use custom headers with the four responses
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="https://MYDOMAIN" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
But now I get Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Why am having to do any of this as it works in dev? Why does IIS seem to only allow one domain for CORS. Isn't the point to all CORS to allow multiple origins?
Why cant I find a solution.