我配置的服务如上所述:
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