这样做是可能的。我已经在这件事上工作了两个星期,到处寻找答案。这是我的做法。
您需要在 Startup.cs 的 Configure 方法中添加 configure app.UseFileServer()
app.UseFileServer(new FileServerOptions
{
PhysicalFileProvider("\\\\virtualPath\\photos\\wait\\"),
RequestPath = new PathString("/AROULETTE"),
EnableDirectoryBrowsing = true
});
这是如何工作的?
它的设置方式,您将输入http://localhost:5000/AROULETTE
它会在浏览器中打开 PhysicalFileProvider 中提供的虚拟路径。当然这不是我真正想要的。
我需要使用 C# 创建一个目录并将文件复制到虚拟目录中。
完成 FileServer 设置后,我尝试了类似的方法,但它不起作用。
if(!Directory.Exists("/AROULETTE/20170814"))
{
Directory.Create("/AROULETTE/20170814")
}
当然,这也不是
var path = Path.Combine("http://localhost:5000/", "AROULETTE/20170814")
if(!Directory.Exists(path)
{
Directory.Create(path)
}
相反,您只需使用文件夹的实际虚拟路径。
if(!Directory.Exists("\\\\virtualPath\\photos\\wait\\20170814"))
{
Directory.Create("\\\\virtualPath\\photos\\wait\\20170814")
}
因此 UseFileServer 用于在应用程序和虚拟文件夹之间创建“桥梁”,就像使用 ASP.Net 4.5 创建虚拟目录一样
希望这可以帮助一些人,因为关于这个主题的大多数答案都不清楚。