浏览代码

开启跨域

lcl 7 月之前
父节点
当前提交
227d43a814
共有 3 个文件被更改,包括 7 次插入7 次删除
  1. 3 3
      Middleware/GlobalExceptionMiddleware.cs
  2. 1 1
      Program.cs
  3. 3 3
      appsettings.Development.json

+ 3 - 3
Middleware/GlobalExceptionMiddleware.cs

@@ -35,9 +35,9 @@ namespace Middleware
             try
             {
                 // 设置允许跨域的域名、方法等
-                // context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
-                // context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
-                // context.Response.Headers.Add("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization");
+                context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
+                context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
+                context.Response.Headers.Add("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization");
 
                 // 如果请求方法是预检请求(OPTIONS),则直接返回成功状态码
                 if (context.Request.Method == "OPTIONS")

+ 1 - 1
Program.cs

@@ -27,7 +27,7 @@ builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
 // builder.Services.AddIPRate(builder.Configuration);
 builder.Services.AddSession();
 builder.Services.AddHttpContextAccessor();
-// builder.Services.AddCors(option => option.AddPolicy("cors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().SetIsOriginAllowed(_ => true)));
+builder.Services.AddCors(option => option.AddPolicy("cors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().SetIsOriginAllowed(_ => true)));
 builder.Services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = true).Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
 
 //绑定整个对象到Model上

+ 3 - 3
appsettings.Development.json

@@ -14,7 +14,7 @@
   },
   "dbConfigs": [
     {
-      "Conn": "server=47.109.61.115;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=PrizeSet;charset=utf8;",
+      "Conn": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=prize_set;charset=utf8;",
       "DbType": 0,
       "ConfigId": "0",
       "IsAutoCloseConnection": true
@@ -22,8 +22,8 @@
   ],
   "RedisServer": {
     "open": 1,
-    "Cache": "47.109.61.115:6379,password=ym87540628,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
-    "Session": "47.109.61.115:6379,password=ym87540628,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
+    "Cache": "47.108.62.166:6379,password=klm@redis,defaultDatabase=5,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
+    "Session": "47.108.62.166:6379,password=klm@redis,defaultDatabase=5,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
   },
   "OssConfigs": {
     "Host": "",