我在 Azure 上的 WebApp 有点问题。我的自定义字体在本地主机上正确呈现,但是当我将项目部署到 Azure 并访问网站时,WebBrowser 通知我找不到我的字体(错误 404)。但是当我从 Azure 门户访问 FTP 服务器时,我可以找到那些字体。 我也试过这个链接的解决方案: http://www.codepal.co.uk/show/WOFF_files_return_404_in_Azure_Web_Sites
但遗憾的是没有任何进展。
最佳答案
I have a little problem with my WebApp on Azure. My custom fonts are rendered properly on my localhost, but when I deploy my project to Azure and visit the WebSite, the WebBrowser is notifying me that my fonts couldn't be found (error 404). But when I visit the FTP Server from Azure Portal I can find those Fonts
原因是 IIS 的 MIME 类型 列表中不存在这些格式,如果您仍然遇到问题并且 IIS 在添加 MIME 类型后仍然无法提供文件,正如 Amey Vaidya 所说,在为这些字体文件重新声明 MIME 类型声明之前,您可以尝试删除 MIME 类型声明。
我这边的同样问题:
项目文件夹结构
注意:我正在使用 sansation_light.woff .
Default.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<style>
@font-face {
font-family: myFirstFont;
src: url(/fonts/sansation_light.woff);
}
#cont {
font-family: myFirstFont;
}
</style>
</head>
<body>
<div>hello world</div>
<br />
<div id="cont">hello world</div>
</body>
</html>
404 错误
添加MIME类型后,就可以正常工作了。
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
</system.webServer>
此外,请确保您在@font-face rule 的src
属性中指定了正确的字体文件URL。 .如果可能,您可以在您的 Azure Web 应用程序环境中测试我的示例代码并检查它是否有效,如果您的 Azure Web 应用程序环境有问题导致问题,您可以尝试将您的项目部署到新的 Azure Web 应用程序和检查它是否可以工作。
关于c# - Azure WebApp 没有加载我的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45534332/