Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core 2 MVC - Font-awesome woff/2 ttf not loading in production

I'm building a personal project and having some issues with font-awesome webfonts not loading. i've made a gulp build to integrate Bootstrap 4 and building all my JS/SCSS/Fonts/Img from a src directory to a dist one. I serve Dist outside of wwwroot

When setting ASPNETCORE_ENVIRONMENT to Development, everything works right, my fonts load correctly but in "Production", it doesnt load and i get the following message in the console:

Failed to load resource: the server responded with a status of 404 (Not Found)fa-regular-400.woff
Failed to load resource: the server responded with a status of 404 (Not Found)fa-regular-400.woff2
Failed to load resource: the server responded with a status of 404 (Not Found) fa-regular-400.ttf

When i mouseover the error i see that they are served from my SrcAssets not the DistAssets like all my other assets files.

I didnt found any working ressources regarding Core2.0 MVC everything i've found is regarding older stuff where these files extensions need to be mapped to for ex. application/font-woff2

Last thing i've tried was this below in the Configure method but it's still doesnt work.

FileExtensionContentTypeProvider typeProvider = new FileExtensionContentTypeProvider();

if (!typeProvider.Mappings.ContainsKey(".woff2"))
{
    typeProvider.Mappings.Add(".woff2", "application/font-woff2");
}
if (!typeProvider.Mappings.ContainsKey(".woff"))
{
    typeProvider.Mappings.Add(".woff", "application/font-woff");
}
if (!typeProvider.Mappings.ContainsKey(".ttf"))
{
    typeProvider.Mappings.Add(".woff", "application/font-ttf");
}

app.UseStaticFiles(new StaticFileOptions
{
    ContentTypeProvider = typeProvider,
    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "DistAssets")),
    RequestPath = "/assets"
});

Thanks for your help.

like image 267
Pascal Ménard Avatar asked Sep 17 '25 19:09

Pascal Ménard


1 Answers

I was have the same issue but I add "../lib/FontAwesome/webfonts" instead "../webfonts" in _variables.scss

$fa-font-path:                "../lib/FontAwesome/webfonts" !default;

Maybe it'll help you too :)

like image 53
Karter Avatar answered Sep 22 '25 10:09

Karter