Axios和.Net Core 跨域配置(当后台启用windows验证的情况)

前台Axios配置:

axios.defaults.withCredentials = true;

.Net Core 后台配置:

#region CORS
            //跨域方法,先注入服务,声明策略,然后再下边app中配置开启中间件
            services.AddCors(c =>
            {
                //一般采用这种方法
                c.AddPolicy("LimitRequests", policy =>
                {

                    policy.AllowCredentials() 
                    .AllowAnyOrigin()
                    //.WithOrigins("http://localhost:8080")//支持多个域名端口,注意端口号后不要带/斜杆
                    .AllowAnyHeader()//Ensures that the policy allows any header.
                    .AllowAnyMethod();
                });
            });

            #endregion
 
 
 
原文地址:https://www.cnblogs.com/Aaron-Lee/p/14004676.html