Hi guys,
I have a solution with 2 projects. A .net 6.0 webAPP and webAPI, the web APP using JQuery to post to the webAPI, however I keep getting CORS policy has been blocked.
I enabled it in the program.cs file in the WebAPP file as below, but does not seem to work. Please help
builder.Services.AddCors(options =>
{
options.AddPolicy("VM_CorsPolicy", builder => {
builder.WithOrigins("*").AllowAnyHeader().AllowAnyMethod();
});
});
// Added after routing and before end points methods
app.UseCors("VM_CorsPolicy");
webAPP or webAPI? Typically CORS is governed by the server so I would think this belongs on the webAPI project. A request is made (either by your webAPP or some other request from someone else) and the server/api determines if the origin in the request is compatible with the policy. If so, then it responds with the resource.
So just to make sure, you are applying CORS logic to your webAPI endpoints (the project offering the resources) right?