1
build / build-push (push) Successful in 27s

This commit is contained in:
wanghu
2026-09-03 20:14:17 +08:00
parent acff097027
commit 07b817ccca
+5 -6
View File
@@ -89,13 +89,12 @@ namespace YhCore.WebApi
// 对象映射:对应 Java ModelMapper // 对象映射:对应 Java ModelMapper
services.AddAutoMapper(typeof(Startup)); services.AddAutoMapper(typeof(Startup));
// 跨域策略:来源白名单(appsettings.json Cors:Origins)+ 允许凭据。 // 跨域策略:允许任意来源 + 允许凭据(等价 Java @CrossOrigin(originPatterns={"*"}, allowCredentials="true"))。
// 响应回 Access-Control-Allow-Origin: <具体来源> 且 Access-Control-Allow-Credentials: true, // SetIsOriginAllowed(_ => true) 会回显任意请求 Origin(而非下发 *),
// 白名单内前端可用 fetch/XHR credentials:'include' 跨域携带 CAS 登录 Cookie。 // 并附 Access-Control-Allow-Credentials: true,使任意来源的前端都能以 credentials:'include' 跨域携带 CAS 登录 Cookie。
// 注意:Cors 规范禁止 * 与凭据同用,故不能用 AllowAnyOrigin。 // 注意:Cors 规范禁止 * 与凭据同用,故不能直接用 AllowAnyOrigin。
var corsOrigins = Configuration.GetSection("Cors:Origins").Get<string[]>() ?? Array.Empty<string>();
services.AddCors(options => options.AddPolicy("default", builder => builder services.AddCors(options => options.AddPolicy("default", builder => builder
.WithOrigins(corsOrigins) .SetIsOriginAllowed(_ => true)
.AllowAnyMethod() .AllowAnyMethod()
.AllowAnyHeader() .AllowAnyHeader()
.AllowCredentials())); .AllowCredentials()));