Search code examples
c#asp.netowinkatana

OWIN self static file server multiple routes


I have configured in my Owin a webApi and an static file server to fetch some files that we will need in my app.

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.
            .....
 }

This is working like a charm. What a I need it's to declare another FileServer for another path and another different physical folder. What I'm frightening is if I do it in the same way I will override this one and I will have only one. So how can I declare a second fileserver?

Thank you.


Solution

  • AFAICT, you can "mount" different FileSystem paths onto different routes, using the same overload you are already using.

    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.
                .....
     }
    

    If you want to have them merged, I don't think it's possible with UseFileServer.

    Am I missing something?