OWIN自静态文件服务器多条路由

时间:2017-02-22 08:25:24

标签: c# asp.net owin katana

我在我的Owin中配置了一个webApi和一个静态文件服务器来获取我们应用程序中需要的一些文件。

public void Configuration(IAppBuilder application)
{
   //Other middlewares and configurations
    ....
   application.UseFileServer(new FileServerOptions()
   {
       RequestPath = new PathString("/myPath1/public"),
       FileSystem = new PhysicalFileSystem(m_FolderPathProvider.myPath1FolderPublic)
   });

       // Attribute routing.
            .....
 }

这就像一个魅力。我需要它为另一个路径和另一个不同的物理文件夹声明另一个FileServer。令我害怕的是,如果我以同样的方式做到这一点,我将覆盖这个,我将只有一个。那么如何声明第二个文件服务器?

谢谢。

1 个答案:

答案 0 :(得分:4)

AFAICT,您可以使用您已经使用的相同重载将不同的FileSystem路径“挂载”到不同的路由上。

public void Configuration(IAppBuilder application)
{
   //Other middlewares and configurations
    ....
   application.UseFileServer(new FileServerOptions()
   {
       RequestPath = new PathString("/myPath1/public"),
       FileSystem = new PhysicalFileSystem(m_FolderPathProvider.myPath1FolderPublic)
   });

   application.UseFileServer(new FileServerOptions()
   {
       RequestPath = new PathString("/myPath2/public"),
       FileSystem = new PhysicalFileSystem(m_FolderPathProvider.myPath2FolderPublic)
   });

       // Attribute routing.
            .....
 }

如果你想让它们合并,我认为UseFileServer不可能。

我错过了什么吗?

相关问题