简体   繁体   English

Azure CDN 上 ttf 字体文件的 CORS 错误

[英]CORS Error with ttf font file on Azure CDN

I have a CDN I have created using the Verizon Premium SKU.我有一个使用 Verizon Premium SKU 创建的 CDN。 when it comes to fonts I get "from origin ' https://myfqdn.com ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource"当涉及到字体时,我得到“来自源 ' https://myfqdn.com ' 已被 CORS 策略阻止:请求的资源上不存在 'Access-Control-Allow-Origin' 标头”

However, I have followed this doc https://docs.microsoft.com/en-us/azure/cdn/cdn-cors with no luck.但是,我已经按照这个文档https://docs.microsoft.com/en-us/azure/cdn/cdn-cors没有运气。

However, if I go to my https://cdn.myfqdn.com (yes I have a custom domain and https enabled) the page loads however with no issues.但是,如果我访问我的https://cdn.myfqdn.com (是的,我有一个自定义域并启用了 https),页面加载但是没有问题。

Here is the XML from the rule that I created from the doc above.这是我从上面的文档创建的规则中的 XML。

 <rules schema-version="2" rulesetversion="6" rulesetid="945266" xmlns="http://www.whitecdn.com/schemas/rules/2.0/rulesSchema.xsd">
  <rule id="1823263" platform="http-large" status="active" version="3" custid="A76A4">
    <!--Changed by userId: 952 on 02/25/2019 03:45:01 PM GMT-->
    <!--Changed by xxx@cdn.windowsazure.com on 02/25/2019 03:25:23 PM GMT from IP: xxx.xxx.xxx.xxx-->
    <description>Wildcard</description>
    <!--If-->
    <match.request-header.wildcard name="Origin" result="match" value="Https://myFQDN.com" ignore-case="true">
      <feature.set-request-header action="set" key="Access-Control-Allow-Origin" value="*" />
      <feature.set-request-header action="set" key="Access-Control-Allow-Headers" value="*" />
      <feature.set-request-header action="set" key="Access-Control-Allow-Methods" value="GET, HEAD, OPTIONS" />
      <feature.set-request-header action="set" key="Access-Control-Expose-Headers" value="*" />
    </match.request-header.wildcard>
  </rule>
</rules>

Thanks for your help谢谢你的帮助

I was also facing this issue in my blog.我在我的博客中也遇到了这个问题。 All the files were loading from the CDN except fonts and icons.除了字体和图标外,所有文件都是从 CDN 加载的。 I had to do two things.我必须做两件事。 One is to allow all the origins in the Azure web app and the other is to configure the files in IIS by editing the web.config .一种是允许 Azure Web 应用程序中的所有来源,另一种是通过编辑web.config来配置 IIS 中的web.config

Just login to your Azure portal, and go to your Azure web application.只需登录到您的 Azure 门户,然后转到您的 Azure Web 应用程序。 Click on the CORS menu under API and * as the allowed origin.单击 API 下的 CORS 菜单并将 * 作为允许的来源。

在此处输入图片说明

By default files with .woff2, .woff, and .ttf extensions are not served by IIS in Azure App Service.默认情况下,带有 .woff2、.woff 和 .ttf 扩展名的文件不是由 Azure 应用服务中的 IIS 提供的。 That is the reason for this CORS issue.这就是这个 CORS 问题的原因。 We will add these configurations in the system.webServer tag which is the child tag of configuration tag.我们将这些配置添加到 system.webServer 标签中,该标签是配置标签的子标签。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
     <staticContent>
      <mimeMap fileExtension="woff" mimeType="application/font-woff" />
      <mimeMap fileExtension="woff2" mimeType="application/font-woff2" />
      <mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".ttc" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".otf" mimeType="application/octet-stream" />
    </staticContent>
  </system.webServer>
</configuration>

You can also do this by adding the extension called “Enable Static Web Fonts”.您也可以通过添加名为“启用静态 Web 字体”的扩展来实现此目的。 I have written a detailed blog about this, you can read it here .我写了一篇关于这个的详细博客, 你可以在这里阅读

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

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