【问题标题】:CORS Issue with AJAX and Azure Reverse ProxyAJAX 和 Azure 反向代理的 CORS 问题
【发布时间】:2017-10-16 21:19:24
【问题描述】:

我遇到了 CORS 问题。 我通过已设置为反向代理和负载均衡器的域 B 从域 A 中的 SPA 到域 C(我的也是)中的 REST API 进行 AJAX 调用。 这三个都部署到 Azure Web Apps。

从 A 到 C 的呼叫直接工作没有问题。 但是通过 B 从 A 到 C 的调用将不起作用。

允许使用门户网站从 A 对 B 和 C 进行 CORS。 使用 Portal 在 B 中的 C 上允许 CORS。

API 服务器 C 的 Web.config 有以下内容:

    <httpProtocol>
      <customHeaders>
          <add name="Access-Control-Allow-Origin" value="*" />
          <add name="Access-Control-Allow-Headers" value="Content-Type" />
          <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
      </customHeaders>
   </httpProtocol>

但我收到以下错误:

    Response to preflight request doesn't pass access control check: 
    No 'Access-Control-Allow-Origin' header is present on the requested resource. 
    Origin 'null' is therefore not allowed access. 
    The response had HTTP status code 400.

所以,我的理解是 API 服务器必须允许 SPA 发出请求,这就是我认为上面的行所做的。那么有人知道这是怎么回事吗?

【问题讨论】:

    标签: ajax azure proxy cors


    【解决方案1】:

    您可以在应用服务中控制 CORS,该设置可能会覆盖您的 web.config。在 App Service 菜单中向下滚动到 API 部分,并且有一个 CORS 菜单。

    由于您指定了一些允许的标头和方法,该部分可能不适合您,但如果您为 * 添加记录,然后将其删除,它应该开始使用基于 web.config 的 CORS 处理。

    【讨论】:

      猜你喜欢
      • 2018-03-03
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 2020-11-30
      • 1970-01-01
      相关资源
      最近更新 更多