1、配置跨域
#region 配置跨域 //配置跨域 builder.Services.AddCors(cor => { var cors = configuration.GetSection("CorsUrls").GetChildren().Select(p => p.Value); cor.AddPolicy("Cors", policy => { policy.WithOrigins(cors.ToArray()) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); #endregion
2、啟用跨域
app.UseCors("Cors");
3、在appsetting.json中配置可跨域操作的ip或者域名
"CorsUrls": [ "http://localhost:3000", "http://localhost:8080", "http://localhost:5000", "https://localhost:5001" ]