【问题标题】:Accessing an IIS Virtual Directory from Dotnet Core从 Dotnet Core 访问 IIS 虚拟目录
【发布时间】:2017-06-13 01:00:58
【问题描述】:

我正在构建一个 Dotnet Core Web 应用程序,该应用程序需要允许经过 Windows 身份验证的用户浏览连接的虚拟目录并查看和选择其中托管的文件。

有没有办法让 Dotnet Core 应用程序访问虚拟目录?除此之外,有没有办法让常规的 Dotnet 应用程序做到这一点?

【问题讨论】:

标签: iis asp.net-core .net-core


【解决方案1】:

这样做是可能的。我已经在这件事上工作了两个星期,到处寻找答案。这是我的做法。

您需要在 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 创建虚拟目录一样

希望这可以帮助一些人,因为关于这个主题的大多数答案都不清楚。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    相关资源
    最近更新 更多