配置跨域策略

This commit is contained in:
lihanbo 2024-10-18 11:29:40 +08:00
parent 47db444117
commit f171251921
1 changed files with 12 additions and 0 deletions

View File

@ -53,6 +53,17 @@ public static class Program
}
});
});
// 配置跨域策略
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAny", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
// 使用Serilog此处为了修复 `The logger is already frozen` 的问题重新配置Serilog
builder.Host.UseSerilog((context, services, config) =>
{
@ -86,6 +97,7 @@ public static class Program
Log.Logger.Information("ApplicationStarted");
CodeFirst.InitTable();
});
app.UseCors("AllowAny");
app.Run();
}