.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"
  },

 

posted @ 2021-04-27 16:44  苍煙落照  阅读(161)  评论(0)    收藏  举报