[ASP.Net] Setting up CORS to allow all origins in ASP.Net 6
발행일: Feb, 2025
조회수: 0
단어수: 38
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");