Azure的云服务CDN字体CORS错误 [英] Azure Cloud Service CDN font CORS error

查看:372
本文介绍了Azure的云服务CDN字体CORS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注这个教程启用的Azure CDN云服务:
链接。我和我的集成捆绑和缩小与CDN和除了我的网站不能获取字体一切正常,我得到这个错误:

I've been following this tutorial for enabling Azure CDN for Cloud Services: link. And I integrated my bundling and minification with CDN and everything works fine except my site cannot fetch fonts, I'm getting this error:

Font from origin 'http://azurecdn.vo.msecnd.net' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http:// mysite.com' is therefore not allowed access.

我累找到从我的问题的解决,并添加这些行到我的Web.config文件:

I tired to find solution from my problem and added these lines to my Web.config file:

  <httpProtocol>
  <customHeaders>
    <add name="access-control-allow-origin" value="*" />
    <add name="access-control-allow-headers" value="content-type" />
  </customHeaders>
</httpProtocol>
   <rewrite>
  <outboundRules>
    <rule name="Set Access-Control-Allow-Origin header">
      <match serverVariable="RESPONSE_Access-Control-Allow-Origin" pattern="(.*)" />
      <action type="Rewrite" value="*" />
    </rule>
  </outboundRules>
  <rules>

    <rule name="RewriteIncomingCdnRequest" stopProcessing="true">
      <match url="^cdn/(.*)$"/>
      <action type="Rewrite" url="{R:1}"/>
    </rule>
  </rules>
</rewrite>

但是,这并没有帮助,我也发现了问题和放大器;答案像这样:链接,但这只是帮助,如果您使用的CDN + BLOB存储(其中我不使用)

But that didn't help, also I found questions & answers such as this: link, but this helps only if you're using CDN + Blob storage (which I'm not using)

我该如何解决呢?

修改

我从包中删除字体和链接时不用CDN和做的伎俩,但就是不完全的解决这个问题。

I removed fonts from my bundle and linked them without CDN and that did the trick, but that isn't exactly solution to this problem

推荐答案

这对于Azure的CDN改写配置工作对我来说...

This rewrite configuration for Azure CDN is working for me...

<rewrite>
    <outboundRules>
        <rule name="Set Access Control Allow Origin Header" preCondition="Origin header">
            <match serverVariable="RESPONSE_Access-Control-Allow-Origin" pattern="(.*)" />
            <action type="Rewrite" value="*" />
        </rule>
        <preConditions>
            <preCondition name="Origin header" logicalGrouping="MatchAll">
                <add input="{HTTP_ORIGIN}" pattern="(.+)" />
                <add input="{HTTP_X_ORIGINAL_URL}" pattern="^/cdn/(.*)$" />
            </preCondition>
        </preConditions>
    </outboundRules>
    <rules>
        <rule name="Rewrite CDN requests" stopProcessing="true">
            <match url="^cdn/(.*)$" />
            <action type="Rewrite" url="{R:1}" />
        </rule>
    </rules>
</rewrite>

有关从Azure的CDN每一个请求(URL开始 CDN / )包含非空的产地: HTTP头它增加了访问控制允许来源:* HTTP头响应

For every request from Azure CDN (url starting with cdn/) containing non empty Origin: http header it adds Access-Control-Allow-Origin: * http header to response.

这篇关于Azure的云服务CDN字体CORS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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