我配置的服務如上所述:
Plugins.Add(new CorsFeature(
allowCredentials: true,
allowedMethods: "GET, POST, PUT, DELETE, OPTIONS",
allowedHeaders: "Content-Type, Allow, Authorization, Origin",
allowOriginWhitelist: new[]
{
"http://localhost:4200",
"http://localhost:63342",
"http://localhost:63342",
"http://localhost:3000",
"http://my.site.com"
}));
和我有2個功能登錄()和GetContacts()
class AppComponent {
***
constructor(){
this.client = new JsonServiceClient("http://my.site.com");
this.client.credentials = "omit";
}
async Login(){
var auth = new wbs.Authenticate();
auth.UserName = this.username;
auth.Password = this.password;
var authResponse = await this.client.post(auth);
console.log(authResponse);
}
async GetContacts(){
try {
this.contacts = await this.client.post("Contacts_Get");
console.log(this.contacts);
} catch(e) {
this.contacts = [];
console.log("Failed to get:", e.responseStatus);
}
}
}
「servicestack客戶端」:「 0.0.30「,
我依次調用這些函數:
1. Login()
2. ContactsGet()
登錄運行良好,但在Internet Explorere和Safari ContactsGet失敗時,它返回狀態401,但在Chrome中運行。
幫忙請在我的錯誤? 謝謝!
UPDATE
IIS設置
仍然不起作用:'對預檢請求的響應未通過訪問控制檢查:響應中的'Access-Control-Allow-Origin'標頭的值在請求的憑證模式下不能爲通配符'*'是'包括'。 Origin'https:/my-app2.azurewebsites.net'因此是不允許訪問的.' – lucuma
我已經更新了答案,將從另一個白名單域中完整地顯示出工作身份驗證示例。 –
我也嘗試過。我想出了這個問題,它不是後端的CORS設置,而是前端的JsonServiceClient。我不得不設置'client.credentials =「omit」'。 – lucuma