DirectoryEntry.Properties["Path"].Value.ToString()

本文关键字:quot ToString Value Properties DirectoryEntry Path | 更新日期: 2023-09-27 18:17:04

当前获得Unknown error (0x80005000) -链接到"COM异常"在c#中运行以下代码时string virtualDirectory = GetVirtualDirPath("IIS://localhost", "1", reportUrl);

static string GetVirtualDirPath(string iisHost,
                                 string siteName, string vdName)
    {
        string adsiPath = iisHost + "/W3SVC/" + siteName + "/Root/test/" + vdName;
        try
        {
            DirectoryEntry entry = new DirectoryEntry(adsiPath);
            return entry.Properties["Path"].Value.ToString();
        }
        catch (Exception ex)
        {
            // If Virtual Directory is not found,
            // it will throw exception.
            return "";
        }
        return "";
    }

我已经在"/test"(http://localhost/test/share)中设置了"share"作为虚拟目录,并尝试赋予该文件夹相关权限。

我读到这只适用于IIS6而不是IIS7?如果是,等效代码是什么?

DirectoryEntry.Properties["Path"].Value.ToString()

IIS7现在公开了一个托管管理API,其信息可以在这里找到。

更具体地说,有便于管理虚拟目录的类。

var iis = new ServerManager();
var site = iis.Sites["SiteName"];
var application = site.Applications["ApplicationName"];
var directories = application.VirtualDirectories;
//proceed to determine the physical path of appropriate directory
var path = directories[0].Path;