1. configservice
//******************* cors start ***********************
var urls = Configuration[SigmalHexConstant.AppConfig_CoresUrls].Split(',');
services.AddCors(
options =>
options.AddPolicy(SigmalHexConstant.DefaultCorsPolicy,
builder => builder.WithOrigins(urls).AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin().AllowCredentials())
);
//******************* cors end ***********************
- 先讀取支持的配置地址;
- 配置默認策略,制定Urls內全部支持
//******************* cors start ***********************
app.UseCors(SigmalHexConstant.DefaultCorsPolicy);
//******************* cors end ***********************
3. 所有Action支持
[EnableCors(SigmalHexConstant.DefaultCorsPolicy)]
public class BaseController : Controller
{
}
ref:http://www.cnblogs.com/xingbo/p/6093325.html