From cf259991b339e82837763627daaaa82941fb9944 Mon Sep 17 00:00:00 2001 From: yiyun Date: Tue, 22 Oct 2024 20:37:21 +0800 Subject: [PATCH] fix(src/knifehub.web/program.cs): cors The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time --- src/KnifeHub.Web/Program.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/KnifeHub.Web/Program.cs b/src/KnifeHub.Web/Program.cs index 088b28b4..9ee0fe9b 100644 --- a/src/KnifeHub.Web/Program.cs +++ b/src/KnifeHub.Web/Program.cs @@ -125,7 +125,15 @@ public static void Main(string[] args) if (configOptions.AllowAllCors) { Log.Information("Cors: AllowAllCors"); - builder.Services.AddCors(m => m.AddPolicy("AllowAllCors", a => a.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials())); + // System.InvalidOperationException: The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time. Configure the CORS policy by listing individual origins if credentials needs to be supported. + builder.Services.AddCors(m => + m.AddPolicy("AllowAllCors", + a => a + //.AllowAnyOrigin() + .SetIsOriginAllowed(_ => true) + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials())); } else {