简体   繁体   English

从桌面应用程序获取虚拟目录的物理路径

[英]Get physical path of virtual directory from desktop application

I have a virtual directory created in IIS named VirtualDir . 我在IIS中创建了一个名为VirtualDir的虚拟目录。 It points to the UNC path \\\\fileserver\\folder1\\folder2\\ 它指向UNC路径\\\\fileserver\\folder1\\folder2\\

I have a desktop application ( HttpContext.Current is not available); 我有一个桌面应用程序( HttpContext.Current不可用); and I'd like to retrieve the UNC path from the virtual directory name. 并且我想从虚拟目录名称中检索UNC路径。

I know that if I was in a web context I could call ServerApplication.MapPath("/VirtualDir/") . 我知道,如果我处于Web上下文中,则可以调用ServerApplication.MapPath("/VirtualDir/") I've tested in a web application and this works, but it doesn't help me. 我已经在Web应用程序中进行了测试,并且可以正常工作,但这对我没有帮助。

I've tried HostingEnvironment.MaptPath("/VirtualDir/") but that returns null. 我已经尝试过HostingEnvironment.MaptPath("/VirtualDir/")但是返回null。

How can I retrieve the physical location of an IIS virtual directory from a desktop application, given the name of the virtual directory (and assuming it is under the default website). 给定虚拟目录的名称(并假设其位于默认网站下),如何从桌面应用程序中检索IIS虚拟目录的物理位置。

Use ServerManager (needs admin privileges) from Microsoft.Web.Administration . 使用Microsoft.Web.Administration中的 ServerManager (需要管理员权限)。 For example 例如

var server = new ServerManager();
var path = server.Sites["Site Name"]
    .Applications["Application Name"]
    .VirtualDirectories["Directory"]
    .PhysicalPath;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM