在Azure Service Bus命名空间上启用CORS [英] Enable CORS on Azure Service Bus Namespace

查看:71
本文介绍了在Azure Service Bus命名空间上启用CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在JavaScript中使用Azure Service Bus REST API.不幸的是,我遇到了跨源问题,因为我的Service Bus名称空间与我的网站不在同一个域中.

I want to use the Azure Service Bus REST API in JavaScript. Unfortunately I'm running into cross origin problems, as my Service Bus namespace is not in the same domain as my site.

我知道您可以为许多Azure服务启用CORS,但是我无法在Azure文档或其他地方找到任何资源来告诉我如何针对服务总线执行此操作.

I know that you can enable CORS with many Azure services, but I can't find any resource in the Azure documentation or elsewhere telling me how to do this for the Service Bus.

有人知道是否以及如何做到这一点?

Does anybody know if, and how, this can be done?

推荐答案

我已经通过使用以下Web.config创建一个单独的Web应用程序解决了这个问题,该应用程序只是一个简单的代理.

I've solved this issue by creating a separate Web App with the following Web.config which is just a simple proxy.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Proxy" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{CACHE_URL}" pattern=".*" />
          </conditions>
          <action type="Rewrite" url="https://mynamespace.servicebus.windows.net/{R:0}" logRewrittenUrl="true" />
      <serverVariables>
        <set name="HTTP_ACCEPT_ENCODING" value="" />
      </serverVariables>
    </rule>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Expose-Headers" value="BrokerProperties" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

这篇关于在Azure Service Bus命名空间上启用CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆