【问题标题】:FontAwesome error in IISIIS 中的 FontAwesome 错误
【发布时间】:2025-11-24 16:00:01
【问题描述】:

在 IIS 中运行时,我的 ASP.Net MVC 页面出现以下错误

可下载字体:下载失败(字体系列:“FontAwesome”样式:正常粗细:正常拉伸:正常 src 索引:1):status=2147746065 来源:http://localhost/MyApp/fonts/fontawesome-webfont.woff?v=4.1.01sharedStyle:1:126778

在本地运行相同的页面,一切正常。部署所有文件 FA 的路径是 C:\inetpub\wwwroot\MyApp\Content\Template\font-awesome-4.1.0

我尝试了Why font-awesome works on localhost but not on web ?ASP.NET MVC4 Bundling with Twitter Bootstrap 的所有解决方案

更新:

我按照 Shyju 的建议将 fileExtensions 添加到 system.webServer,但并没有改变问题。

捆绑有可能有问题吗?我使用它的方式如下:

public static void RegisterBundles(BundleCollection bundles)
{
  StyleBundle sharedStyleBundle = new StyleBundle("~/bundles/sharedStyle");
  sharedStyleBundle.Include("~/Content/Template/font-awesome-4.1.0/css/font-awesome.css");
  ...
  bundles.Add(sharedStyleBundle);
  ...
}

【问题讨论】:

    标签: css asp.net-mvc-4 iis font-awesome


    【解决方案1】:

    IIS 不知道如何处理这些新类型的文件。我们应该明确指出这些是很好的文件类型。

    将此部分添加到 <system.webServer> 部分下的 web.config 中。那应该可以解决它。

    <staticContent>   
      <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />      
      <mimeMap fileExtension=".otf" mimeType="font/otf" />     
      <mimeMap fileExtension=".woff" mimeType="font/x-woff" />     
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
    </staticContent>
    

    有时,如果已添加,则需要将其删除并重新添加以避免可能的冲突/错误。

    <staticContent>
      <remove fileExtension=".eot" />
      <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
      <remove fileExtension=".otf" />
      <mimeMap fileExtension=".otf" mimeType="font/otf" />
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
    </staticContent>
    

    【讨论】:

      【解决方案2】:

      我必须按如下方式更改捆绑:

      public static void RegisterBundles(BundleCollection bundles)
      {
        StyleBundle sharedStyleBundle = 
          new StyleBundle("~/Content/Template/font-awesome-4.1.0/css/bundle");
        sharedStyleBundle
          .Include("~/Content/Template/font-awesome-4.1.0/css/font-awesome.css");
        bundles.Add(sharedStyleBundle);
        ...
      }
      

      似乎很重要,捆绑包的键与捆绑包路径本身具有相同的结构。

      【讨论】: