application/font-woff2 not working when using Asp.Net VNext
asp.netasp.net Mvc-5Woff2asp.net Problem Overview
I'm doing some experiments with VNext + OSX + Chrome. I'm trying to get a woff2 file
GET http://localhost:5003/fonts/fontawesome-webfont.woff2?v=4.3.0
But an error occur. See the request's header below
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
This is my 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" });
});
}
I saw inside AspNet project at Github about StaticFiles (Link bellow) and it seems to be supported.
Can you guys give me some help?
asp.net Solutions
Solution 1 - asp.net
The file format woff2
is in the mapping list but this was added recently (February 2015) so you may not use a release that contains this change. So to add a custom file format you can use the IIS way using web.config
:
<system.webServer>
<staticContent>
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
</system.webServer>
Or using 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);
}
Solution 2 - asp.net
add a mime type declaration to your web.config
<system.webServer>
<staticContent>
<mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
for more info see:
Solution 3 - asp.net
If above did not work for you (didn't work for me). Then try with this one :
<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
Solution 4 - asp.net
add mime type in plesk
application/font-woff2 .woff2
it worked for me
Solution 5 - asp.net
I needed to enable the extension first (which could be done in IIS too) like:
<system.webServer>
...
<security>
<requestFiltering>
<fileExtensions>
<remove fileExtension=".woff2" />
<add fileExtension=".woff2" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
...
</system.webServer>
as well as adding the previously mentioned static content...
<system.webServer>
...
<staticContent>
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
...
</system.webServer>