我刚刚在Azure上部署了一个新的web应用程序,API和DB。作为测试,我让大约六个人使用这个应用程序。它对五个人有效,但有一个人出现了CORS错误:
SEC7120:[CORS]起源
https://mysite.azurewebsites.net
没有
查找'
https://mysite.azurewebsites.net
'在
访问控制允许跨源资源的源响应标头
at'
https://mysiteapi.azurewebsites.net/user
'.
这怎么可能?架构如下:
浏览器>Azure Web应用程序>Azure API>Azure数据库
CORS问题在Azure Web App和Azure API之间,对吗?那么,当每个用户的web应用程序和API之间没有任何变化时,一个人怎么会有这个问题呢?
在我的。NET核心3.0 API,我有这个
app.UseCors(options => options
.WithOrigins("http://localhost:4200", "https://localhost:4200", "https://mysite.azurewebsites.net")
.AllowAnyMethod()
.WithHeaders("Authorization", "Content-Type"));
我的web应用程序调用API如下:
const headers_object = new HttpHeaders().set("Authorization", "Bearer " + jwt);
this.http.get('user', { headers: headers_object, responseType: 'json' })
.subscribe((data: any) => {
this.userDto = data;
},
error => {
console.log('error: ', error);
});
那么,它怎么可能表现得不同呢?为什么会发生这种情况?