I have a strange problem with preflight requests.
This is how it looks in the Chrome (and other chromium based browsers) after doing something in our application:
Many preflight requests are marked red as failed (net::ERR_FAILED).
One of such failed preflights:
But in the end, there is a preflight request for each request, that succeeds with 204 and the application works correctly. So it looks like the browser tries it few times and ultimately it's ok, but many items in the log are red...
In the Firefox preflight requests are not even visible and it looks like everything is fine:
In the API, in Program.cs, we have such a code, which should make it always work, with AllowAnyMethod(), which should accept any OPTIONS requests:
var allowedOrigins = app.Configuration.GetSection("appSettings") != null
? app.Configuration.GetSection("appSettings").GetSection("AllowedCorsOrigins").GetChildren().Select(x => x.Value).ToArray()
: Array.Empty<string>();
Trace.WriteLine("allowed origins:" + string.Join(',', allowedOrigins));
app.UseCors(x => x
.WithOrigins(allowedOrigins)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.WithExposedHeaders("Content-Disposition"));
I also tried this solution with the use of middleware: https://stackoverflow.com/a/42199758/3153226 But it works the same.
What can be the reason that Chrome is making so many failed preflight requests? Is it normal? Is it a Chrome bug, network error or API error?
Thank you for your answers. I can add more information, just tell me what you need to know.
Btw I don't have any CORS errors in the console log.