title: Access to fetch at 'https://localhost:44395' from origin 'null' has been blocked by CORS policy
body: <p>I have <strong>Asp .net core 3</strong> web API. I am calling one of the POST API using Fetch then getting the following errors:</p>
  <pre><code>Access to fetch at 'https://localhost:44395/api/challengeresponse/Verify' from origin 'null' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
  Failed to load resource: net::ERR_FAILED
  </code></pre>
  <p>So I research and try following in Web API code:</p>
  <blockquote>
  <p>Startup.cs</p>
  </blockquote>
  <pre><code>private readonly string AllowedOriginPolicy = &quot;_AllowedOriginPolicy&quot;;
  public void ConfigureServices(IServiceCollection services)
          {
              services.AddCors(options =&gt;
              {
                  options.AddPolicy(AllowedOriginPolicy,
                      builder =&gt;
                      {
                          var corsOrigins = new String[1] { &quot;https://localhost:44395&quot; };
  
                          builder.WithOrigins(corsOrigins).AllowCredentials().AllowAnyHeader().AllowAnyMethod();
                      });
              });
  
              services.AddControllers();
          }
  
  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  {
     app.UseCors(AllowedOriginPolicy); //at the end of the method.
  }
  </code></pre>
  <p>Still, I am getting the same errors.</p>
  <p>My Fetch code is:</p>
  <blockquote>
  <p>sample.js</p>
  </blockquote>
  <pre><code>async function fetchdata(){
      let _data = {
          OriginalData: &quot;coordinateid&quot;,
          Signature: &quot;URL&quot;,
          Certificate: &quot;introduction&quot;
      }
  
      const response = await fetch('https://localhost:44395/api/challengeresponse/Verify', {
       credentials: 'include',
       method: &quot;POST&quot;,
       body: JSON.stringify(_data),
       headers: {&quot;Content-type&quot;: &quot;application/json; charset=UTF-8&quot;}
  })
  .then(response =&gt; response.json()) 
  .then(json =&gt; console.log(json))
  .catch(err =&gt; console.log(err));
  }
  </code></pre>
  <p>It is a very common question but still, I am not able to solve. Please help.</p>
  <p>Edit: Please suggest for <code>http://</code> and <code>https://</code> both type of URL's. Because I also deployed this web API on the main server, and accessing from server URL also gives the same error.</p>