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

aco*_*ela 2 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.
            .....
 }
Run Code Online (Sandbox Code Playgroud)

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

谢谢你。

A. *_*esa 5

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

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.
            .....
 }
Run Code Online (Sandbox Code Playgroud)

如果您想让它们合并,我认为UseFileServer.

我错过了什么吗?