DirectoryEntry.Properties[“路径”].Value.ToString(); IIS7问题。 C#

发布于 2024-12-20 13:31:39 字数 864 浏览 2 评论 0原文

当前出现未知错误 (0x80005000) - 运行以下代码时链接到 C# 中的“COM 异常” 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 "";
    }

我已将“share”设置为“/test”内的虚拟目录(http://localhost/test /share)并尝试授予该文件夹相关权限。

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

Currently getting Unknown error (0x80005000) - Linked to "COM Exception" in C# when running the following code
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 "";
    }

I have setup "share" as a Virtual Directory inside "/test" (http://localhost/test/share) and tried giving that folder relevant permissions.

I have read that this only works in IIS6 and Not IIS7? If so, what is the equivalent code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆消瘦 2024-12-27 13:31:39

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;

IIS7 now exposes a managed management API, information of which can be found here.

More specifically, there are classes to facilitate management of virtual directories.

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文