Asp.Net Core2.0允许跨域请求设置
程序员文章站
2022-03-29 13:42:48
1、services 2、app ......
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 }
上一篇: 复制和删除txt文件
下一篇: 解决api、WebService跨域问题