From aa8a1f9196f38a4c267c0d52dd0b02de09879917 Mon Sep 17 00:00:00 2001 From: zpc Date: Fri, 1 Aug 2025 14:51:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/WebExtensions/CorsExtension.cs | 2 ++ ZR.Admin.WebApi/Program.cs | 5 +++++ ZR.Admin.WebApi/appsettings.json | 6 +++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Infrastructure/WebExtensions/CorsExtension.cs b/Infrastructure/WebExtensions/CorsExtension.cs index 37fc224..b8cb642 100644 --- a/Infrastructure/WebExtensions/CorsExtension.cs +++ b/Infrastructure/WebExtensions/CorsExtension.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; + using System; namespace Infrastructure @@ -28,6 +29,7 @@ namespace Infrastructure .AllowCredentials()//允许cookie .AllowAnyMethod();//允许任意方法 }); + }); } } diff --git a/ZR.Admin.WebApi/Program.cs b/ZR.Admin.WebApi/Program.cs index 2d360f6..1e919d4 100644 --- a/ZR.Admin.WebApi/Program.cs +++ b/ZR.Admin.WebApi/Program.cs @@ -14,6 +14,7 @@ using ZR.ServiceCore.Signalr; using ZR.ServiceCore.SqlSugar; using ZR.Mall; using SKIT.FlurlHttpClient.Wechat.Api; +using Infrastructure; //using SQLitePCL; var builder = WebApplication.CreateBuilder(args); @@ -31,7 +32,9 @@ builder.Services.AddSwaggerGen(); //注入HttpContextAccessor builder.Services.AddSingleton(); // 跨域配置 +#if DEBUG builder.Services.AddCors(builder.Configuration); +#endif //消除Error unprotecting the session cookie警告 builder.Services.AddDataProtection() .PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection")); @@ -155,7 +158,9 @@ app.Use((context, next) => app.UseStaticFiles(); //开启路由访问 app.UseRouting(); +#if DEBUG app.UseCors("Policy");//要放在app.UseEndpoints前。 +#endif //app.UseHttpsRedirection(); app.UseAuthentication(); diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index 671c93d..9dbac39 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -8,7 +8,7 @@ }, "dbConfigs": [ { - "Conn": "Data Source=192.168.1.41;User ID=sa;Password=Dbt@com@123;Initial Catalog=ZrAdmin;Encrypt=True;TrustServerCertificate=True;", + "Conn": "Data Source=192.168.195.8;User ID=sa;Password=Dbt@com@123;Initial Catalog=ZrAdmin;Encrypt=True;TrustServerCertificate=True;", "DbType": 1, //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3,PgSql = 4 "ConfigId": "0", //多租户唯一标识 "IsAutoCloseConnection": true @@ -25,12 +25,12 @@ //代码生成数据库配置 初始化数据:http://localhost:8888/common/initseedData "CodeGenDbConfig": { //代码生成连接字符串,注意{dbName}为固定格式,不要填写数据库名 - "Conn": "Data Source=192.168.1.41;User ID=sa;Password=Dbt@com@123;Encrypt=True;TrustServerCertificate=True;Initial Catalog={dbName};", + "Conn": "Data Source=192.168.195.8;User ID=sa;Password=Dbt@com@123;Encrypt=True;TrustServerCertificate=True;Initial Catalog={dbName};", "DbType": 1, "IsAutoCloseConnection": true, "DbName": "ZrAdmin" //代码生成默认连接数据库,Oracle库是实例的名称 }, - "urls": "http://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改 + "urls": "http://*:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改 "corsUrls": [ "http://localhost:8887", "http://localhost:8886" ], //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开 "JwtSettings": { "Issuer": "ZRAdmin.NET", //即token的签发者。