0

有沒有人有使用Web Api Core和CORS進行匿名身份驗證和Windows身份驗證的經驗?本質上我需要啓用Windows身份驗證,但是當我這樣做時CORS請求PUT和POST失敗,因爲預檢請求被拒絕。我已經使用下面的代碼正確啓用CORS,但似乎沒有任何工作。.Net Core CORS 401 POST/PUT

  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

回答

0

您還需要

app.UseCors("CorsPolicy"); 

Configure方法。

+1

我在控制器上有它,所以不應該在配置中需要它 –