How to fix 'woff and ttf fonts 404 not found'

By FoxLearn 2/18/2024 12:58:45 AM   256
When publishing your web site to IIS or running your project in Visual Studio and you encounter errors.

"Failed to load resource: the server responded with a status of 404 (Not Found)" or "woff2?v=4.3.0 Failed to load resource" with fontawesome-webfont.wofffontawesome-webfont.woff2glyphicons-halflings-regular.woffglyphicons-halflings-regular.woff2.

If you haven't got files, i think you should download then copy to your project. First ensure that you copy all files to webserver, In Visual Studio you can click each of file then select properties->copy always

Second you need to open the Web.config file then add a config as below

<staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff2" mimeType="font/x-woff" />
 </staticContent>

Now, Start your project again then select inspect->tab network you can see no error throw a 404 not found error on woff or woff2 files when requesting the .woff, .ttf, .woff2 files