Asp.net core mvc ASP.NET Core 2 MVC-生产中未加载字体awesome woff/2 ttf
我正在构建一个个人项目,但在字体方面遇到了一些问题,webfonts无法加载。我已经做了一个gulp构建来集成bootstrap4,并将我所有的JS/SCSS/Fonts/Img从src目录构建到dist目录。我在wwwroot以外的地区服务 将ASPNETCORE_环境设置为Development时,一切正常,我的字体加载正确,但在“Production”中,它不会加载,我在控制台中收到以下消息:Asp.net core mvc ASP.NET Core 2 MVC-生产中未加载字体awesome woff/2 ttf,asp.net-core-mvc,asp.net-core-mvc-2.0,Asp.net Core Mvc,Asp.net Core Mvc 2.0,我正在构建一个个人项目,但在字体方面遇到了一些问题,webfonts无法加载。我已经做了一个gulp构建来集成bootstrap4,并将我所有的JS/SCSS/Fonts/Img从src目录构建到dist目录。我在wwwroot以外的地区服务 将ASPNETCORE_环境设置为Development时,一切正常,我的字体加载正确,但在“Production”中,它不会加载,我在控制台中收到以下消息: Failed to load resource: the server responded wi
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的可用资源。我发现的一切都是关于旧的东西,这些文件扩展名需要映射到旧的东西,例如application/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"
});
谢谢你的帮助。我也有同样的问题,但我在
\u variables.scss中添加了。/lib/FontAwesome/webfonts“
。/webfonts”
$fa-font-path: "../lib/FontAwesome/webfonts" !default;
也许它也会对您有所帮助:)尝试将此代码添加到您的web.config
<configuration>
....
<system.webServer>
<staticContent>
<mimeMap fileExtension="woff" mimeType="font/woff" />
</staticContent>
</system.webServer>
</configuration>
....