diff --git a/CoreCms.Net.Core/Config/CorsSetup.cs b/CoreCms.Net.Core/Config/CorsSetup.cs index 9b9d1e7..4c41a50 100644 --- a/CoreCms.Net.Core/Config/CorsSetup.cs +++ b/CoreCms.Net.Core/Config/CorsSetup.cs @@ -33,9 +33,10 @@ namespace CoreCms.Net.Core.Config { c.AddPolicy(AppSettingsConstVars.CorsPolicyName, policy => { - policy.WithOrigins(AppSettingsConstVars.CorsIPs.Split(',')) - .AllowAnyHeader()//Ensures that the policy allows any header. - .AllowAnyMethod(); + policy.WithOrigins(AppSettingsConstVars.CorsIPs.Split(',')); + policy.AllowAnyHeader();//Ensures that the policy allows any header. + policy.AllowAnyMethod(); + policy.AllowCredentials(); }); } else diff --git a/CoreCms.Net.Web.WebApi/Startup.cs b/CoreCms.Net.Web.WebApi/Startup.cs index fee1318..ebd5e4f 100644 --- a/CoreCms.Net.Web.WebApi/Startup.cs +++ b/CoreCms.Net.Web.WebApi/Startup.cs @@ -84,6 +84,9 @@ namespace CoreCms.Net.Web.WebApi //添加数据库连接SqlSugar注入支持 services.AddSqlSugarSetup(); + //配置跨域(CORS) + services.AddCorsSetup(); + //添加session支持(session依赖于cache进行存储) services.AddSession(); @@ -296,6 +299,7 @@ namespace CoreCms.Net.Web.WebApi #endregion + //使用 Session app.UseSession(); @@ -311,6 +315,9 @@ namespace CoreCms.Net.Web.WebApi app.UseHsts(); } + // CORS跨域 + app.UseCors(AppSettingsConstVars.CorsPolicyName); + // Routing app.UseRouting();