I am getting following error while accessing Angular app through browser (chrome/Edge/Firefox/Opera). API request works on direct calls from well through Postman/Fiddler.
So i think there something between Cloudfront and EC2 calls and CORS policy
Following is my set up.
Angular Setup:
.netcore web api setup:
services.AddCors(options =>
{
options.AddPolicy("EnableCORS", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
added CORS middleware
app.UseCors("EnableCORS");
Have added required Annotation over APi Controllers
[EnableCors("EnableCORS")]
Not sure what am i missing along this setup.
Finally got it worked with few changes to my setup of CORS in .netcore code and IIS. Following are the changes.
AllowAnyOrigion()
to WithOrigins("https://xxx.xxxx.com")
to sum it up instead of trying to manage CORS headers from IIS, I left it to Kestral.
Still not sure what was the exact issue.