简体   繁体   中英

MVC Cannot locate font files after publishing to IIS

Franework ASP.Net MVC 4

This is another instance of "it worked until I published".

Running my MVC 4 site from Visual studio, everything works great. However, when I publish - font awesome breaks. Looking at the Chrome console, I am seeing this:

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

Which is referenced in my CSS like this:

@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;
}

And I have checked - the files are in the site directory:

在此处输入图片说明

What am I doing wrong?

I have a feeling you need to add the MIME types to the web.config of your application (or globally in the IIS manager).

Try adding:

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

to your web.config.

If you run into duplicate key issues that means your IIS instance has some of these extensions already. To allow you to control the MIME type for all the extensions, add:

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

before the <mimeMap> elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM