From 106914fa74e917b9ec11bc5819d864733fb89ad5 Mon Sep 17 00:00:00 2001 From: JianWeie Date: Wed, 2 Jun 2021 14:55:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96h5=E8=B7=A8=E5=9F=9F=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreCms.Net.Core/Config/CorsSetup.cs | 7 ++++--- CoreCms.Net.Web.WebApi/Startup.cs | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) 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();