title: Failed to enable CORS in asp .net core 6.0 Web Api
body: <p>I am working a asp .net core 6.0 web Api.(We are moving to asp .net core from 3.1 to 6.0)</p>
  <p>I did enable cors in our asp .net core 6.0 project and works fine earlier (this morning ). But Now I faced cors error.</p>
  <p><strong>Error:</strong>
  <code>Access to XMLHttpRequest at 'http://localhost:5000/api/user/authenticate' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.</code></p>
  <p>I revoked my git commits and checked. still It give CORS error</p>
  <p>This is my program.cs</p>
  <pre><code>var app = builder.Build();
  
  app.UseHttpsRedirection();
  app.UseForwardedHeaders();
  app.UseCors(builder =&gt; builder.WithOrigins(&quot;*&quot;)/*.AllowAnyOrigin()*/.AllowAnyHeader().AllowAnyMethod());
  app.UseRouting();
  app.UseAuthentication();
  app.UseAuthorization();
  </code></pre>
  <p>The same code worked fine earlier in asp .net core 6.0.
  Also Now In asp .netcore 3.1 project It is working fine.</p>
  <p>Note: I searched about this error. And Tried same as on this answer <a href="https://stackoverflow.com/questions/70511588/how-to-enable-cors-in-asp-net-core-6-0-web-api-project">How to enable cors in ASP.NET Core 6.0 Web API project?</a>. But It did not work for me.</p>
  <p>What  is the mistake I did?
  Why this error occurs ( Today morning I did not face this error. But now facing this error. I revoked my new commits too. But CORS error)</p>
  <p><strong>Is there any other reasons to get this CORS error. I guess mistake is on my asp.net core 6.0 project, because asp .net core 3.1 project is working fine</strong></p>