title: How to enable Cors for every type of request in asp.net core 3.1
body: <p>How to enable Cors for every type of request in asp.net core 3.1?</p>
  
  <p>I am following the <a href="https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-3.1" rel="nofollow noreferrer">MS Docs</a> but they seem to not work.</p>
  
  <p>Note: I am able to achieve cors for specific domains but not to every domain. For example the below configuration I have applied to my project:</p>
  
  <ol>
  <li><p>In the <code>ConfigureServices();</code> method I added:</p>
  
  <p>services.AddCors();</p></li>
  <li><p>In the <code>Configure()</code> method I added:</p>
  
  <p>app.UseCors(builder =>
  {
      builder
      .WithOrigins()
      .AllowAnyMethod()
      .AllowAnyHeader()
      .AllowCredentials();
  });</p></li>
  </ol>
  
  <p>But when I try to access the API with jQuery from another url then I get:</p>
  
  <blockquote>
    <p>Access to XMLHttpRequest at '<a href="https://localhost:44314/Reservation" rel="nofollow noreferrer">https://localhost:44314/Reservation</a>' from origin '<a href="https://localhost:44361" rel="nofollow noreferrer">https://localhost:44361</a>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.</p>
  </blockquote>
  
  <p>Now If i put the URL in the WithOrigins() method I am able to access the API:</p>
  
  <pre><code>app.UseCors(builder =&gt;
  {
      builder
      .WithOrigins("https://localhost:44361")
      .AllowAnyMethod()
      .AllowAnyHeader()
      .AllowCredentials();
  });
  </code></pre>
  
  <p>My question is how to give access to the API to every URL(i.e domain, subdomain,etc) without restriction. Applying * does not work. </p>
  
  <p>Please help. </p>