首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从owin FileServer服务FileServer文件

如何从owin FileServer服务FileServer文件
EN

Stack Overflow用户
提问于 2015-02-11 14:43:10
回答 2查看 1.2K关注 0票数 1

由于字体可怕的4.3,他们添加字体为woff2格式。

当我试图通过owin提供此文件时,我正在引导404 to:

代码语言:javascript
复制
app.UseFileServer(new FileServerOptions() {
    RequestPath = PathString.Empty,
    FileSystem = new PhysicalFileSystem(@"banana")
});

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-10 14:33:22

您可以通过使用继承来避免不太好的转换:

代码语言:javascript
复制
FileServerOptions options = new FileServerOptions
{
    StaticFileOptions =
    {
        ContentTypeProvider = new CustomFileExtensionContentTypeProvider(),
    }
};

哪里

代码语言:javascript
复制
private class CustomFileExtensionContentTypeProvider : FileExtensionContentTypeProvider
{
    public CustomFileExtensionContentTypeProvider()
    {
        Mappings.Add(".json", "application/json");
        Mappings.Add(".mustache", "text/template");
    }
}
票数 2
EN

Stack Overflow用户

发布于 2015-02-11 14:43:10

有两种可能性:

  • 服务所有类型的文件类型:

代码语言:javascript
复制
var options = new FileServerOptions() {
    RequestPath = PathString.Empty,
    FileSystem = new PhysicalFileSystem(@"banana")
};

options.StaticFileOptions.ServeUnknownFileTypes = true;

app.UseFileServer(options);
  • 添加woff2 mime类型:

代码语言:javascript
复制
var options = new FileServerOptions() {
    RequestPath = PathString.Empty,
    FileSystem = new PhysicalFileSystem(@"banana")
};

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

app.UseFileServer(options);

第二种选择似乎不那么优雅,但仍然是最好的选择。读why mime types are important

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28457090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档