【问题标题】:MVC Cannot locate font files after publishing to IISMVC 发布到 IIS 后找不到字体文件
【发布时间】:2014-05-11 05:21:10
【问题描述】:

框架 ASP.Net MVC 4

这是“在我发布之前一直有效”的另一个实例。

从 Visual Studio 运行我的 MVC 4 站点,一切正常。然而,当我发布 - 字体真棒休息。查看 Chrome 控制台,我看到了这个:

GET http://localhost:4321/Content/themes/crisp/font/zocial.woff?94486700 404 (Not Found)

在我的 CSS 中是这样引用的:

@font-face {
  font-family: 'zocial';
  src: url('/Content/themes/crisp/font/zocial.eot?94486700');
  src: url('/Content/themes/crisp/font/zocial.woff?94486700') format('woff'),
       url('/Content/themes/crisp/font/social.ttf?94486700') format('truetype'),
       url('/Content/themes/crisp/font/zocial.svg?94486700#fontello') format('svg');
  font-weight: normal;
  font-style: normal;
}

我已经检查过 - 文件在站点目录中:

我做错了什么?

【问题讨论】:

  • 不知道在哪里可以问这个,但是,你如何把截图放在帖子里?
  • @CSharper 在您问题顶部的工具栏中,有一个看起来像宝丽来的按钮,可让您上传图像。

标签: c# css asp.net-mvc asp.net-mvc-4


【解决方案1】:

我感觉您需要将 MIME 类型添加到应用程序的 web.config(或全局地在 IIS 管理器中)。

尝试添加:

<system.webServer>
    <staticContent>
        <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
        <mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        <mimeMap fileExtension=".woff" mimeType="application/x-woff" />
    </staticContent>
</system.webServer>

到您的 web.config。

如果您遇到重复的关键问题,这意味着您的 IIS 实例已经具有其中一些扩展。要允许您控制所有扩展的 MIME 类型,请添加:

<remove fileExtension=".woff" />
<remove fileExtension=".eot" />
<remove fileExtension=".svg" />
<remove fileExtension=".ttf" />

&lt;mimeMap&gt; 元素之前。

【讨论】:

  • 像冠军一样工作。谢谢!
  • 我现在遇到了同样的问题。但问题是如果我使用&lt;staticContent&gt; 没有加载 css,js 文件,如果我删除它,除了字体,一切都运行良好。请帮忙
  • @RajSan 我认为需要更多信息来帮助您。我会问一个新问题,参考这个问题和你的情况信息。这将使整个社区也可以阅读和回答您的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多