Quellcode durchsuchen

跨域代码关闭

lcl vor 3 Wochen
Ursprung
Commit
a983dca408
2 geänderte Dateien mit 4 neuen und 4 gelöschten Zeilen
  1. 3 3
      Middleware/GlobalExceptionMiddleware.cs
  2. 1 1
      Program.cs

+ 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上