我正在用VNext+OSX+Chrome做一些实验。我正在尝试获取一个woff2文件
GET http://localhost:5003/fonts/fontawesome-webfont.woff2?v=4.3.0
但是出现了一个错误。请参阅下方的请求标题
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(链接如下)的内容,它似乎得到了支持。
https://github.com/aspnet/StaticFiles/blob/dev/src/Microsoft.AspNet.StaticFiles/FileExtensionContentTypeProvider.cs
你们能帮我一下吗?
文件格式woff2
在映射列表中,但它是最近添加的(2015年2月),因此您可能不会使用包含此更改的版本。因此,要添加自定义文件格式,可以使用IIS方式使用web.config
:
<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);
}
将mime类型声明添加到web.config
<system.webServer>
<staticContent>
<mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
有关更多信息,请参阅:
在IIS 中设置web字体的mime类型
快速修复:在asp.net mvc 中找不到IIS.woff字体文件404
如果以上内容对您不起作用(对我不起作用)。然后试试这个:
<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
在plesk 中添加mime类型
application/font-woff2 .woff2
它对我有效
我需要首先启用扩展(这也可以在IIS中完成),比如:
<system.webServer>
...
<security>
<requestFiltering>
<fileExtensions>
<remove fileExtension=".woff2" />
<add fileExtension=".woff2" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
...
</system.webServer>
以及添加前面提到的静态内容。。。
<system.webServer>
...
<staticContent>
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
...
</system.webServer>