不知道为什么,在2.2中的跨域配置在3.1中使用会发生问题:Access to XMLHttpRequest at 'http://xx.xx.xx.xx/api/' from origin 'http://localhost:8082' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.改动了一下startup.cs中的配置,ConfigureServices修改如下:
services.AddCors(options =>
{
options.AddPolicy("any", builder =>
{
builder.WithOrigins("http://127.0.0.1:8080")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()//指定处理cookie
.WithExposedHeaders("Content-Disposition");//指定处理cookie
});
});
在3.0中AllowAnyOrigin()已不能使用, 然后新增一个