CSS 字体在 IIS 8.0 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25796609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:35:24  来源:igfitidea点击:

Font Face isn't working in IIS 8.0

cssiisfontswoff2

提问by joetinger

I have a font-face in my program generated from Font Squirrel I just can't get it to work in IIS, it works in localhost. I added application/font-woffarticleto my MIME Types but it still doesn't want to work.

我的程序中有一个由 Font Squirrel 生成的字体,我只是无法让它在 IIS 中工作,它在 localhost 中工作。我在 MIME 类型中添加了application/font-woff文章,但它仍然不想工作。

Context
--Fonts
----font location
--css files

CSS

CSS

@font-face {
    font-family: 'wallStreetFont';
    src: url('Fonts/subway-webfont.eot');
    src: url('Fonts/subway-webfont.eot?#iefix') format('embedded-opentype'),
         url('Fonts/subway-webfont.woff2') format('woff2'),
         url('Fonts/subway-webfont.woff') format('woff'),
         url('Fonts/subway-webfont.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

EDIT CURRENT MIME

编辑当前 MIME

I am using the default IIS 8 MIME font/x-woff

我正在使用默认的 IIS 8 MIME字体/x-woff

回答by Colin Bacon

Great to see WOFF2 being included in Font Squirrel fonts! Whilst IIS 8 does not need a mime type added for WOFFit will need one for WOFF2. The W3C recommends:

很高兴看到 WOFF2 被包含在 Font Squirrel 字体中!虽然 IIS 8 不需要添加 MIME 类型,因为WOFF它需要一个用于WOFF2. W3C建议

application/font-woff2

For more info on WOFF2see here.

有关更多信息,WOFF2请参见此处

To add the mime type in IIS, modify your Web.Configas follows:

要在 IIS 中添加 mime 类型,请Web.Config按如下方式修改:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <!-- ... -->
  <system.webServer>
    <!-- ... -->
    <staticContent>
      <!-- ... -->
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
    </staticContent>
    <!-- ... -->
  </system.webServer>

回答by Varun

In order to make woff and woff2 fonts to properly work in IIS you should add the following MIME types to the Web.Config file.

为了使 woff 和 woff2 字体在 IIS 中正常工作,您应该将以下 MIME 类型添加到 Web.Config 文件中。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>  
  <system.webServer>    
    <staticContent>
        <remove fileExtension=".woff" />
        <remove fileExtension=".woff2" />
        <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
        <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
    </staticContent>

If you still face the 404 error on Google Chrome you should clear your browser cache before reloading the page.

如果您在 Google Chrome 上仍然遇到 404 错误,您应该在重新加载页面之前清除浏览器缓存。

回答by Scott Munro

Note that it is also possible to configure MIME types within IIS Manager. Just select the website and then double click on the MIME Types icon under IIS in the main pane.

请注意,也可以在 IIS 管理器中配置 MIME 类型。只需选择网站,然后双击主窗格中 IIS 下的 MIME 类型图标。

enter image description here

在此处输入图片说明

You should then see a list of all of the existing MIME Types and be able to add new ones using the Add... link in the right pane.

然后,您应该会看到所有现有 MIME 类型的列表,并且能够使用右侧窗格中的添加...链接添加新的类型。

回答by Giulio

I was having this issue today while deploying a Web solution Metro4 UI icons and switching from the CDN to the Compiled option.

我今天在部署 Web 解决方案 Metro4 UI 图标并从 CDN 切换到已编译选项时遇到了这个问题。

My project was developed using WebSharper platform, but the solution is anyway independent from these implementation details.

我的项目是使用 WebSharper 平台开发的,但解决方案无论如何都独立于这些实现细节。

Long story short, I've discover that I had to add the file extension, e.g. for .ttf, inside the securitysection under the system.webServerof the Web.config.

长话短说,我已经发现,我不得不添加的文件扩展名,例如,对于.ttf,里面的security部分下system.webServerWeb.config

<security>
    <requestFiltering>
        <fileExtensions>
            <add fileExtension=".ttf" allowed="true" />
        </fileExtensions>
    </requestFiltering>
</security>

The same configuration option is also available under the GUI settings of IIS

在 IIS 的 GUI 设置下也可以使用相同的配置选项

IIS GUI

图形用户界面