Question: I have a React frontend that calls a dotnet core backend API. When certain errors happen, nothing gets logged, and the response causes the front end to show a CORS error. While I believe there is an actual CORS error happening, it's not happening because of the code itself, but because of something going on in the exception handling part of the dotnet library. Has anyone else seen this? While I cannot reproduce the problem, I have seen it fixed by changing some database flags, etc. meaning there is an error happening, but before it can be logged or shown to the user, the stack blows up and a CORS error is shown at the React level.

Answer: 
Hint: It could be a Middleware you attached via

`app.UseMiddleware<YourMiddleware>();`

that gets executed during pre-flight.

I am referring to `.net 5` as I had the same issue recently that my React application showed CORS issues while they were not. The backend simply crashed on the pre-flight.

It should show up in your console or add the classic

```
if (env.IsDevelopment())
{
  app.UseDeveloperExceptionPage();
}

```
I fixed most of my CORS issues by adding this to the startup,cs:

```
services.AddRazorPages().AddRazorPagesOptions(options =>
{
    options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
});

```

And making sure my javascript posts using the following headers:

```
Content-type, application/x-www-form-urlencoded
Access-Control-Allow-Origin, *

```

I'd suggest you just need the C# example.