When starting a WebAPI project, there are times when you need to allow all origins for testing purposes. You can achieve this by adding a simple CORS policy named corsapp and calling app.UseCors after building the application, as shown below:
builder.Services.AddCors(p => p.AddPolicy("corsapp", builder =>
{
builder.WithOrigins("*").AllowAnyMethod().AllowAnyHeader();
}));
var app = builder.Build();
app.UseCors("corsapp");ยฉ 2025 juniyunapapa@gmail.com.