在编写前端代码的过程中经常会遇到使用特定的字体(*.woff,*.svg),此时在加载字体时请求会被返回

Failed to load resource: the server responded with a status of 404 (Not Found)。

原因是,默认在IIS上是没有添加对*.woff,*.svg文件的Mime类型,因此在客户端请求此类文件时得到的都是404。

所以我们只需要在我们对应网站下的Mime类型中添加文件对应的类型就行了

 

  1. .woff  application/x-font-woff
  2. .woff2 application/x-font-woff
  3. .svg   image/svg+xml

另外在mvc中,设置了上述Mime类型后get请求字体时任然会出现404的问题,这个时候需要在我们的web工程中的config的system.webServer节点中添加如下的代码来支持

 

<staticContent>
      <remove fileExtension=".woff"/>
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
      <remove fileExtension=".woff2"/>
      <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" />
      <remove fileExtension=".ttf" />
      <mimeMap fileExtension=".ttf" mimeType="application/x-font-truetype" />
      <remove fileExtension=".svg" />
      <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
      <remove fileExtension=".otf" />
      <mimeMap fileExtension=".otf" mimeType="application/x-font-opentype" />
      <remove fileExtension=".eot" />
      <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
    </staticContent>

 

相关文章:

  • 2022-01-14
  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
  • 2021-12-26
  • 2021-03-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2022-01-17
相关资源
相似解决方案