在 Azure CDN 中提供托管字体时出现 CORS 错误
CORS error when serving hosted fonts in Azure CDN
我们正在尝试使用 Azure CDN 端点为我们的网站启用 CDN。
对于 CSS 和 JavaScript 资源和图像,它工作得很好。但出于某种原因,我们的字体出现了 CORS 错误。
错误是:
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. Origin 'http://[URL-to-testsite]' is therefore not allowed
access.
我们已尝试在 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>
…但不幸的是它根本没有改变任何东西。
有什么建议吗?
在 returns 字体的处理程序中添加以下 HttpHeader 成功了:
Response.AppendHeader("Access-Control-Allow-Origin", siteName);
如果有人有 better/prettier 解决方案,我会洗耳恭听。
我们正在尝试使用 Azure CDN 端点为我们的网站启用 CDN。
对于 CSS 和 JavaScript 资源和图像,它工作得很好。但出于某种原因,我们的字体出现了 CORS 错误。
错误是:
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. Origin 'http://[URL-to-testsite]' is therefore not allowed access.
我们已尝试在 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>
…但不幸的是它根本没有改变任何东西。
有什么建议吗?
在 returns 字体的处理程序中添加以下 HttpHeader 成功了:
Response.AppendHeader("Access-Control-Allow-Origin", siteName);
如果有人有 better/prettier 解决方案,我会洗耳恭听。