简体   繁体   English

在Azure CDN中提供托管字体时出现CORS错误

[英]CORS error when serving hosted fonts in Azure CDN

We are trying to CDN enable our WebSite using Azure CDN endpoints. 我们正在尝试使用Azure CDN终结点CDN启用我们的WebSite。

For CSS and JavaScript resources and images, it works just fine. 对于CSS和JavaScript资源和图像,它可以正常工作。 But for some reason we get CORS errors for our fonts. 但是由于某种原因,我们的字体会出现CORS错误。

The error is: 错误是:

Access to Font at ' http://[name].azureedge.net/-/design/[long-path]/icons.woff ' from origin ' http://[URL-to-testsite] ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 来源' http:// [URL-to-testsite] '对' http:// [name] .azureedge.net /-/ design / [long-path] /icons.woff '处字体的访问已被阻止CORS政策:所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://[URL-to-testsite] ' is therefore not allowed access. 因此,不允许访问来源' http:// [URL-to-testsite] '。

We have tried to insert the following URL-rewrite rules in our web.config : 我们试图在我们的web.config插入以下URL重写规则:

<rewrite>
  <outboundRules>
    <rule name="Set Access-Control-Allow-Origin header">
      <match serverVariable="RESPONSE_Access-Control-Allow-Origin" pattern="(.*)" />
      <action type="Rewrite" value="*" />
    </rule>
  </outboundRules>
</rewrite>

…but unfortunately it did not change anything at all. …但是不幸的是,它根本没有改变任何东西。

Any suggestions? 有什么建议么?

It worked to add the following HttpHeader in the Handler that returns fonts: 它在返回字体的处理程序中添加了以下HttpHeader:

Response.AppendHeader("Access-Control-Allow-Origin", siteName);

If anyone has a better/prettier solution I am all ears. 如果有人有更好/更漂亮的解决方案,我将不胜感激。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM