60

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.

https://github.com/aspnet/StaticFiles/blob/dev/src/Microsoft.AspNet.StaticFiles/FileExtensionContentTypeProvider.cs

Can you guys give me some help?

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
Austin Felipe
  • 779
  • 1
  • 6
  • 11
  • possible duplicate of [Font Face isn't working in IIS 8.0](http://stackoverflow.com/questions/25796609/font-face-isnt-working-in-iis-8-0) – Charles Burns Sep 15 '15 at 15:55
  • @CharlesBurns actually, my post isn't about II8 specifically and the other solution won't work because I'm not working with Web.Config. They are not the same solution. Not even the same question. – Austin Felipe Sep 15 '15 at 20:26
  • Both accepted answers mention the same edit Web.Config and both refer to adding a MIME type to prevent a 404 error. The other question mentions IIS8 in title only, not tags. It does look like both involved *two* problems: MIME types for both, pre-release software in one, a typo in the other. I'll remove my close vote. – Charles Burns Sep 15 '15 at 20:38
  • This question and answer also applies to v=4.3.0. It solves the issues i had in my project. Thanks – vivek Jun 28 '16 at 09:22

5 Answers5

131

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);
}
meziantou
  • 20,589
  • 7
  • 64
  • 83
16

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:

Set mime types for web fonts in IIS

Quick fix: IIS .woff font file 404 not found in asp.net mvc

Harsh Baid
  • 7,199
  • 5
  • 48
  • 92
  • 1
    In case someone else has issues, try removing the . in .woff2, that fixed it for me after I added the above mimeMap to my web.config. – devfunkd Apr 30 '15 at 17:27
2

If above did not work for you (didn't work for me). Then try with this one :

<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
Krika
  • 453
  • 7
  • 20
  • Worked for me as well. I guess the entry that they built in includes the . in the fileExtension because when I add the map with .woff2 as the extension I get an error that there is a duplicate entry. When I removed the . it started working. Great find! – Mike Devenney Jun 23 '17 at 19:48
0

add mime type in plesk

application/font-woff2  .woff2

it worked for me

Prince Prasad
  • 1,528
  • 1
  • 16
  • 20
0

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>
peterr
  • 93
  • 1
  • 5