Search code examples
mime-typesowinfont-awesomefileserverwoff2

How to serve woff2 files from owin FileServer


Since font awesome 4.3, they added the fonts as woff2 format.

I'm guetting 404ed when trying to serve this file through owin :

app.UseFileServer(new FileServerOptions() {
    RequestPath = PathString.Empty,
    FileSystem = new PhysicalFileSystem(@"banana")
});

How do I serve woff2 mime type files through file server in owin ?


Solution

  • You can avoid the not-very-nice casting by using inheritance:

    FileServerOptions options = new FileServerOptions
    {
        StaticFileOptions =
        {
            ContentTypeProvider = new CustomFileExtensionContentTypeProvider(),
        }
    };
    

    where

    private class CustomFileExtensionContentTypeProvider : FileExtensionContentTypeProvider
    {
        public CustomFileExtensionContentTypeProvider()
        {
            Mappings.Add(".json", "application/json");
            Mappings.Add(".mustache", "text/template");
        }
    }