.net core 实现跨域
1、设置允许所有来源跨域
在StartUp类的ConfigureServices方法中添加如下代码
// 配置跨域处理,允许所有来源 services.AddCors(options => options.AddPolicy("AllCors", p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials()));
2、修改Configure方法
// 允许所有跨域,AllCors是在ConfigureServices方法中配置的跨域策略名称 app.UseCors("AllCors");
3、跨域中cookie使用
前端Ajax添加以下参数:
xhrFields: { withCredentials: true }, crossDomain: true,

浙公网安备 33010602011771号