如何从owin FileServer提供woff2文件

Flo*_* F. 0 fileserver mime-types font-awesome owin woff2

由于字体很棒4.3,他们将字体添加为woff2格式.

当我试图通过owin提供这个文件时,我正在问404:

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

如何通过owin中的文件服务器提供woff2 mime类型文件?

Flo*_* F. 8

两种可能性:

  • 提供各种文件类型:
var options = new FileServerOptions() {
    RequestPath = PathString.Empty,
    FileSystem = new PhysicalFileSystem(@"banana")
};

options.StaticFileOptions.ServeUnknownFileTypes = true;

app.UseFileServer(options);
Run Code Online (Sandbox Code Playgroud)
  • 添加woff2 mime类型:
var options = new FileServerOptions() {
    RequestPath = PathString.Empty,
    FileSystem = new PhysicalFileSystem(@"banana")
};

((FileExtensionContentTypeProvider)options.StaticFileOptions.ContentTypeProvider)
    .Mappings.Add(".woff2", "application/font-woff2");

app.UseFileServer(options);
Run Code Online (Sandbox Code Playgroud)

第二种选择似乎并不优雅,但仍然是最好的选择.了解为什么mime类型很重要.