Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

What am I doing wrong?

like image 683
drewwyatt Avatar asked Dec 03 '25 10:12

drewwyatt


1 Answers

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.

like image 90
Steven V Avatar answered Dec 06 '25 00:12

Steven V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!