Network trace error
I implemented CORS policy for an ASP.NET Core 6 Web API, but when the frontend makes an API call, it still results in a CORS error. What could be the issue?
I have tried adjusting the URL and how I defined the policy, however it still prevents all origin from calling the API including the one specified.
please note that, the frontend is unable to call the api immediately the policy is defined.
builder.Services.AddAuthorization();
builder.Services.AddControllers().AddJsonOptions(x =>
x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles);
//Cors Policy
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin",
builder =>
{
builder.WithOrigins("https://apps.example.biz:8090")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials(); // If you need to allow credentials
});
});
//after other definitions in the pipeline then i have this.
app.UseHsts();
app.UseHangfireDashboard("/HangFireDash", new DashboardOptions
{
Authorization = new[] { new HangfireAuthorizationFilter() }
});
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors("AllowSpecificOrigin");
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
12