Enable CORS on Azure Service Bus Namespace

旧巷老猫 提交于 2019-12-05 18:12:30
Blackhex

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 REST API supports CORS by default. All origins are accepted.

To be honest this is not an Azure specific. If you are using jQuery you need to enable cross-domain request option, read more here http://api.jquery.com/jQuery.ajax/. There is also a JavaScript ServiceBus SDK: https://github.com/ddobric/ServiceBusJavaScriptSdk

Generally from the purity point of view calling Service Bus from client side doesn't look good, I'd rather wrap that call into your own API. But I don't know your scenario and it might be valid.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!