c# - Azure WebApp 没有加载我的字体

标签 c# asp.net-mvc azure-web-app-service

我在 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 类型声明。

我这边的同样问题:

项目文件夹结构

enter image description here

注意:我正在使用 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 错误

enter image description here

添加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>

enter image description here

此外,请确保您在@font-face rulesrc 属性中指定了正确的字体文件URL。 .如果可能,您可以在您的 Azure Web 应用程序环境中测试我的示例代码并检查它是否有效,如果您的 Azure Web 应用程序环境有问题导致问题,您可以尝试将您的项目部署到新的 Azure Web 应用程序和检查它是否可以工作。

关于c# - Azure WebApp 没有加载我的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45534332/

相关文章:

c# - 无法在 C# 中使用 CAMLQuery 从 SharePoint 列表中检索列表项

c# - 无法使用 EF 交换两行上的唯一值

javascript - 如何从 ".js"文件运行 url?

c# - 从数据库中搜索并使用 Entity Framework 进行排序

azure - 获取应用服务环境中内部负载均衡器的IP

c# - Azure Web App 部署 msdeploy 包时出现错误

c# - 无法通过 Entity Framework 从 WPF 数据网格更新数据库

C# 字典访问

c# - 为什么发送列表以查看它返回正确的长度但所有字段都是空的?

azure - 启用专用端点后,无法从 ACR 中提取 WebApp 中的图像