1、services
1 /// <summary> 2 /// 3 /// </summary> 4 /// <param name="services"></param> 5 public void ConfigureServices(IServiceCollection services) 6 { 7 #region 允许跨域请求 8 services.AddCors(options => 9 { 10 options.AddPolicy("CorsPolicy", 11 builder => builder 12 .AllowAnyOrigin() 13 .AllowAnyMethod() 14 .AllowAnyHeader() 15 .AllowCredentials()); 16 }); 17 #endregion 18 }
2、app
1 /// <summary> 2 /// 3 /// </summary> 4 /// <param name="app"></param> 5 /// <param name="env"></param> 6 /// <param name="loggerFactory"></param> 7 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 8 { 9 #region 允许跨域请求 10 app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials()); 11 #endregion 12 }