Here is my CORS configuration:
services.AddCors(options =>
{
options.AddPolicy(name: \"AllowedOrigins\",
policyBuilder =>
{
You need to explicitly call app.UseExceptionHandler(...)
in your startup.
If you do not, then unhandled exceptions bubble up the call stack all the way to Kestrel. And Kestrel does not call the delegates hooked up to HttpContext.Response.OnStarting(...)
. CorsMiddleware
(and many other middleware) use OnStarting
to hook into adding information to the response.