Ver código fonte

修复没有配置跨域异常的问题

zhontai 3 anos atrás
pai
commit
b755753eee
2 arquivos alterados com 12 adições e 5 exclusões
  1. 9 5
      Admin.Core/Startup.cs
  2. 3 0
      Admin.Tools/Captcha/Dtos/CaptchaOutput.cs

+ 9 - 5
Admin.Core/Startup.cs

@@ -112,7 +112,8 @@ namespace Admin.Core
             {
                 options.AddPolicy(DefaultCorsPolicyName, policy =>
                 {
-                    if (_appConfig.CorUrls?.Length > 0)
+                    var hasOrigins = _appConfig.CorUrls?.Length > 0;
+                    if (hasOrigins)
                     {
                         policy.WithOrigins(_appConfig.CorUrls);
                     }
@@ -122,8 +123,12 @@ namespace Admin.Core
                     }
                     policy
                     .AllowAnyHeader()
-                    .AllowAnyMethod()
-                    .AllowCredentials();
+                    .AllowAnyMethod();
+
+                    if (hasOrigins)
+                    {
+                        policy.AllowCredentials();
+                    }
                 });
 
                 /*
@@ -134,8 +139,7 @@ namespace Admin.Core
                     .AllowAnyOrigin()
                     .SetPreflightMaxAge(new TimeSpan(0, 10, 0))
                     .AllowAnyHeader()
-                    .AllowAnyMethod()
-                    .AllowCredentials();
+                    .AllowAnyMethod();
                 });
                 */
             });

+ 3 - 0
Admin.Tools/Captcha/Dtos/CaptchaOutput.cs

@@ -10,6 +10,9 @@
         /// </summary>
         public string Token { get; set; }
 
+        /// <summary>
+        /// 数据
+        /// </summary>
         public object Data { get; set; }
     }
 }