在startup.cs中
1.Startup类下定义:readonly string MyAllowSpecificOrigins = "_customSpecificOrigins";
2.ConfigureServices方法内加:
services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
builder =>
{
builder.WithOrigins("http://dgc-pc.zhijiaxing.net",
"https://dgc-pc.zhijiaxing.net",
"https://dgc-api.zhijiaxing.net/",
"http://dgc-api.zhijiaxing.net/",
"http://123.56.26.99:9053",
"https://123.56.26.99:9053",
"http://123.56.26.99:9050/",
"https://123.56.26.99:9050/",
"http://localhost:8080")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
.WithExposedHeaders("errcode", "errmsg");
});
});
3.Configure方法内,app.UseRouting();后面加:
app.UseCors(MyAllowSpecificOrigins);