I am trying to enable CORS in Startup.cs with no luck. I have an Angular app on port 4200 trying to communicate with my c# Web app. I keep getting this error in Angular
Failed to load http://localhost:52008/Account/GetJWT: Response for preflight does not have HTTP ok status.
My research seems to indicate CORS is not being enabled properly. Any idea what I'm missing?
public void ConfigureServices(IServiceCollection services)
{
.....
services.AddCors(options =>
{
options.AddPolicy("EnableCORS", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.Build();
});
});
.........
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
.......
app.UseCors("EnableCORS");
........
}
And heres the Angular POST request:
login(form: NgForm) {
let credentials = JSON.stringify(form.value);
console.log(credentials);
this.http.post("http://localhost:52008/Account/GetJWT", credentials, {
headers: new HttpHeaders({
"Content-Type": "application/json"
})
})
}
Result of POSTMAN query