title: Response to preflight request doesn't pass access control check : asp-net core
body: <p>I know this is a famous error but I'm unable to fix it after trying various solutions.</p>
  
  <p>The request I'm sending is through Angular 2 app. Here's the code for the client request:</p>
  
  <pre><code>async registerAdmin(admin: SystemAdminRegistrationViewModel) {
  
      let response = await this.http.post(this.Account_API_URL + 'accounts/createaccount', admin).toPromise();
      return response;
  }
  </code></pre>
  
  <p>I'm using asp.net core 2 web api project for the API. In my Startup.cs class, I have this:</p>
  
  <pre><code>    services.AddCors(o =&gt; o.AddPolicy("MyPolicy", build =&gt;
              {
                  build.AllowAnyOrigin()
                         .AllowAnyMethod()
                         .AllowAnyHeader();
              }));
  
  
  
              app.UseCors("MyPolicy");
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I forgot to mention that the request works fine when I run the API locally however the error shows up for the request to remote server which is hosted by Azure.</p>