我正在使用 VNext + OSX + Chrome 进行一些实验。我正在尝试获取 woff2 文件
GET http://localhost:5003/fonts/fontawesome-webfont.woff2?v=4.3.0
但是发生错误。请参阅下面的请求 header
Remote Address:127.0.0.1:5003
Request URL:http://localhost:5003/fonts/fontawesome-webfont.woff2?v=4.3.0
Request Method:GET
Status Code:404 Not Found
这是我的 Startup.cs
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseServices(services =>
{
services.AddMvc();
});
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
我在 Github 的 AspNet 项目内部看到了有关 StaticFiles 的内容(链接如下),它似乎受到支持。
你们能给我一些帮助吗?
最佳答案
文件格式 woff2
位于 mapping list 中但这是最近添加的(2015 年 2 月),因此您可能无法使用包含此更改的版本。因此,要添加自定义文件格式,您可以使用 web.config
的 IIS 方式:
<system.webServer>
<staticContent>
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
</system.webServer>
或使用StaticFilesOptions
:
public void Configure(IApplicationBuilder app)
{
StaticFileOptions options = new StaticFileOptions();
FileExtensionContentTypeProvider typeProvider = new FileExtensionContentTypeProvider();
if (!typeProvider.Mappings.ContainsKey(".woff2"))
{
typeProvider.Mappings.Add(".woff2", "application/font-woff2");
}
options.ContentTypeProvider = typeProvider;
app.UseStaticFiles(options);
}
关于asp.net - 使用 Asp.Net VNext 时 application/font-woff2 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28746721/