๐Ÿ˜œ

์ญˆ๋‚˜์•„๋น  ๋ธ”๋กœ๊ทธ

JUNA
STUDIO

[ASP.Net] Setting up CORS to allow all origins in ASP.Net 6

๋ฐœํ–‰์ผ: Feb, 2025
์กฐํšŒ์ˆ˜: 1
๋‹จ์–ด์ˆ˜: 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");

Tags: #CORS#WebAPI#.NET#Cross-Origin Resource Sharing#API Security
JUNA BLOG VISITORS
Today
7
 (
updown
-7
)
Total
657
 (
updown
+7
)

ยฉ 2025 juniyunapapa@gmail.com.