【发布时间】:2018-04-21 21:09:46
【问题描述】:
我正在构建一个个人项目,但遇到了一些字体很棒的网络字体无法加载的问题。我做了一个 gulp 构建来集成 Bootstrap 4 并将我所有的 JS/SCSS/Fonts/Img 从 src 目录构建到 dist 目录。我在 wwwroot 之外为 Dist 服务
将 ASPNETCORE_ENVIRONMENT 设置为开发时,一切正常,我的字体正确加载,但在“生产”中,它没有加载,我在控制台中收到以下消息:
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
当我将鼠标悬停在错误上时,我看到它们是从我的 SrcAssets 提供的,而不是像我的所有其他资产文件一样的 DistAssets。
我没有找到任何关于 Core2.0 MVC 的可用资源,我发现的所有内容都是关于需要将这些文件扩展名映射到的旧东西。应用程序/font-woff2
我尝试过的最后一件事是在 Configure 方法中,但它仍然不起作用。
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"
});
感谢您的帮助。
【问题讨论】:
标签: asp.net-core-mvc asp.net-core-mvc-2.0