.NetCore3.1跨域配置

一、ConfigureServices中注册服务

 var corsArray = configuration["AllowedHosts:MyCors"].Split(',');
            services.AddCors(option =>
                {
                    option.AddPolicy(name: "MyCors", policy =>
                     {
                         policy.AllowAnyHeader()
                         .AllowAnyMethod()
                         .AllowCredentials()
                         .AllowAnyOrigin()
                         .WithOrigins(corsArray);
                     });
                }
            );

二、appsettings.json中进行配置

"AllowedHosts": {
    "MyCors": "http://localhost:7512,http://22.11.111.111:8888,http://localhost:18010"
  },
原文地址:https://www.cnblogs.com/ABC-wangyuhan/p/14709674.html