title: Enabling CORS in .net core Web api and angular 6
body: <p>Here I'm using an HTTP POST request from <code>Angular 6</code> and it is hitting in the .net core Web API call, but I'm not getting the response output back to <code>Angular 6</code> and in console got an error that:</p>
  
  <blockquote>
    <p>"Access to XMLHttpRequest at '<a href="http://localhost:55654/api/login/auth" rel="nofollow noreferrer">http://localhost:55654/api/login/auth</a>'
    from origin '<a href="http://localhost:4200" rel="nofollow noreferrer">http://localhost:4200</a>' has been blocked by CORS policy:
    No 'Access-Control-Allow-Origin' header is present on the requested
    resource."</p>
  </blockquote>
  
  <p>But I'm a bit confused that if it is any <code>CORS</code> enabling access issue, it won't hit the web API call. But it hits the API call and I'm not getting the response back.</p>
  
  <p><code>Angular 6 HTTP POST</code> request:</p>
  
  <pre><code>this.http.post("http://localhost:55654/api/login/auth", credentials, {
    headers: new HttpHeaders({
   "Content-Type": "application/json"
        })
    }).subscribe(response =&gt; {
        let token = (&lt;any&gt;response);
        localStorage.setItem("jwt", token);
      }, err =&gt; {
  
      });
  </code></pre>
  
  <p>I've enabled the <code>CORS</code> in following methods in <code>.NetCore Web API</code></p>
  
  <p><code>Configure</code> Method in <code>Startup.cs</code>:</p>
  
  <pre><code>...
  app.UseCors(options =&gt;
    options.WithOrigins("http://localhost:4200")
      .AllowAnyMethod()
      .AllowAnyHeader());
   ...
  </code></pre>
  
  <p><code>ConfigureServices</code> Method in <code>Startup.cs</code>:</p>
  
  <pre><code>...
  services.AddCors();
  ...
  </code></pre>