代码之家  ›  专栏  ›  技术社区  ›  Bob Horn

为什么我部署的Azure应用程序在CORS方面只适用于一个用户?

  •  0
  • Bob Horn  · 技术社区  · 4 年前

    我刚刚在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);
          });
    

    那么,它怎么可能表现得不同呢?为什么会发生这种情况?

    0 回复  |  直到 4 年前
        1
  •  -1
  •   Bob Horn    4 年前

    出于某种原因,我儿子没有从谷歌OAuth中获得“family_name”的声明。这导致了一个异常,出于某种原因,出现了CORS错误。