在添加完跨域配置,部署服务器时发现无法跨域,本地是正常的。
builder.Services.AddCors(options => options.AddPolicy("AllCors", p => p .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials() .SetIsOriginAllowed(_ => true) ));
app.UseCors("AllCors");
在部署的站点文件,修改web.config,加入如下配置
<system.webServer> <httpProtocol> <customHeaders> <remove name="Access-Control-Allow-Origin" /> <remove name="Access-Control-Allow-Methods" /> <remove name="Access-Control-Allow-Headers" /> </customHeaders> </httpProtocol> </system.webServer>