NetCore+Axios 跨域 请求option预检 不完全解决



我的版本为NET6
builder.Services.AddCors(options =>//限制跨域网站
{
    options.AddPolicy(name: CustomCorsPolicy, policy =>
    {
        // 设定允许跨域的来源,有多个可以用','隔开
        policy.WithOrigins("http://localhost:8888")//"https://localhost:8887", "https://localhost:8889", 
        .AllowAnyHeader()
        .AllowAnyMethod()
        .SetPreflightMaxAge(TimeSpan.FromSeconds(1000L))//预检缓存最大时间
        .AllowCredentials();
    });
    //所有都可以访问
    //services.AddCors(option => option.AddPolicy("cors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().AllowAnyOrigin()));
});

 

 


posted @ 2022-03-24 23:10  孤海飞雁  阅读(276)  评论(0)    收藏  举报