Font Face isn't working in IIS 8.0

泪湿孤枕 提交于 2019-11-28 16:04:32

问题


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-woff article to my MIME Types but it still doesn't want to work.

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

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

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


回答1:


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

application/font-woff2

For more info on WOFF2 see here.

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

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



回答2:


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.

<?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.




回答3:


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.

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.




回答4:


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

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

Long story short, I've discover that I had to add the file extension, e.g. for .ttf, inside the security section under the system.webServer of the Web.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



来源:https://stackoverflow.com/questions/25796609/font-face-isnt-working-in-iis-8-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!