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

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

问题描述

我一直在遵循本教程,为云服务启用Azure CDN:
链接。和我集成我的绑定和缩小与CDN和一切正常,除非我的网站无法获取字体,我得到这个错误:

 源于http://azurecdn.vo.msecnd.net的字体已被跨源资源共享策略阻止加载:在请求的资源上没有Access-Control-Allow-Origin头。原因'http:// mysite.com'因此不允许访问。 

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

 < httpProtocol> 
< customHeaders>
< add name =access-control-allow-originvalue =*/>
< add name =access-control-allow-headersvalue =content-type/>
< / customHeaders>
< / httpProtocol>
< rewrite>
< outboundRules>
< rule name =Set Access-Control-Allow-Origin header>
< match serverVariable =RESPONSE_Access-Control-Allow-Originpattern =(。*)/>
< action type =Rewritevalue =*/>
< / rule>
< / outboundRules>
< rules>

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

但这没有帮助,我也发现了问题&这样的答案:链接,但这只有当您使用CDN + Blob存储(这我不使用)



我如何解决这个问题?



EDIT



我从我的包裹中删除了字体,

$ p

解决方案

回答这个问题,以防它帮助其他人寻找一个办法。
在Azure CDN中,您可以在Verizon Premium配置文件上设置规则,以启用CORS。



https://azure.microsoft.com/en-us/documentation/articles/cdn-cors/

这还允许您指定允许访问的域的明确列表,而不只是通配符。


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.

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>

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)

How can I solve this ?

EDIT

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

解决方案

Answering this in case it helps other people looking for a solution. In Azure CDN, you can set rules on the Verizon Premium profile to enable CORS as well.

https://azure.microsoft.com/en-us/documentation/articles/cdn-cors/

This will also allow you to specify an explicit list of domains allowed access instead of just a wildcard.

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

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