2

I'm building a Dotnet Core web app that needs to allow the Windows-Authenticated user to browse through the connected virtual directories and view and select files hosted there.

Is there a way for a Dotnet Core application to access a virtual directory? And barring that, is there a way for a regular Dotnet application to do it?

BenWurth
  • 790
  • 1
  • 7
  • 23
  • 2
    Possible duplicate of [Virtual directory inside of ASP.NET Core app in IIS](https://stackoverflow.com/questions/36030121/virtual-directory-inside-of-asp-net-core-app-in-iis) – natemcmaster Jun 13 '17 at 04:16
  • Thanks, guys. I think that gave me the resounding "No" that I needed. – BenWurth Jun 13 '17 at 15:10

1 Answers1

5

It is possible to do so. I've been working on this thing for two weeks now, looked everywhere to get an answer. Here is how I did it.

You will need to add in the configure app.UseFileServer() in the Configure method of the Startup.cs

app.UseFileServer(new FileServerOptions
{
    PhysicalFileProvider("\\\\virtualPath\\photos\\wait\\"),
    RequestPath = new PathString("/AROULETTE"),
    EnableDirectoryBrowsing = true
});

How does this work? The way it is set up, you would enter http://localhost:5000/AROULETTE and it would open the virtual path provided in the PhysicalFileProvider in the browser. Of course this is not what I actually wanted.

I needed to create a directory and copy files into the virtual directory with C#. Once I had the FileServer setup, I tried something like this which does not work.

if(!Directory.Exists("/AROULETTE/20170814"))
{
    Directory.Create("/AROULETTE/20170814")
}

of course, neither does this

var path = Path.Combine("http://localhost:5000/", "AROULETTE/20170814")
if(!Directory.Exists(path)
{
    Directory.Create(path)
}

Instead, you just use the actual virtual path of the folder.

if(!Directory.Exists("\\\\virtualPath\\photos\\wait\\20170814"))
{
    Directory.Create("\\\\virtualPath\\photos\\wait\\20170814")
}

Thus UseFileServer is used to create a "bridge" between the application and the virtual folder the same way that you would create a virtual directory with ASP.Net 4.5

Hope this can help some people because most of the answers about this topic were not clear at all.

Ben Lefebvre
  • 359
  • 5
  • 21