有没有人具有使用Web Api Core和CORS进行匿名身份验证和Windows身份验证的经验?本质上,我需要启用Windows身份验证,但是这样做时,由于预检请求被拒绝,因此对PUT和POST的CORS请求失败。我已使用以下代码正确启用了CORS,但似乎无济于事。
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.WithOrigins(new string[] { "http://localhost:3000" })
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
以下问题恰好是我的情况,但是有一个可以接受的答案,既不起作用,又有错误的配置数据。
Angular4 ASP.NET Core 1.2 Windows Authentication CORS for PUT and POST Gives 401
最佳答案
你还需要
app.UseCors("CorsPolicy");
在
Configure
方法中。