Owin PhysicalFileSystem - 嵌入式资源

时间:2015-12-30 11:46:28

标签: c# owin embedded-resource katana

我是Owin的新手,我有一个高级问题,我希望有可能这样做。

我有一个Web应用程序HTML / JS / CSS,我配置了Owin Like This

        var url = "http://localhost:8080";
        var root = args.Length > 0 ? args[0] : ".";
        var fileSystem = new PhysicalFileSystem(root);

        var options = new FileServerOptions();
        options.EnableDirectoryBrowsing = true;
        options.FileSystem = fileSystem;
        options.StaticFileOptions.ContentTypeProvider = new CustomContentTypeProvider();
        options.EnableDefaultFiles = true;


        WebApp.Start(url, builder => builder.UseFileServer(options));
        Console.WriteLine("Listening at " + url);
        Console.ReadLine();

当我在子文件夹中添加项目并导航到它时,确实有效。如:http://localhost:8080/test/

我想要做的是将文件从物理目录移动到嵌入式资源,并将此嵌入资源作为owin的项目文件夹/路径。

我能这样做吗?我怎样才能实现这个目标!!

1 个答案:

答案 0 :(得分:1)

您需要使用EmbeddedResourceFileSystem。然后换行:

options.FileSystem = new EmbeddedResourceFileSystem(typeof(YourClass).Assembly);