【问题标题】:Can I use DirectoryEntry to list sites within IIS Express我可以使用 DirectoryEntry 列出 IIS Express 中的站点吗
【发布时间】:2012-11-21 16:24:18
【问题描述】:

我使用的是 Windows XP。我们有 Windows 2008 服务器。需要运行 IIS Express,直到我们获得具有更新版本本地操作系统的工作站或虚拟机。对于真正的 IIS 7.X。

当我在 IIS Express 下运行 c# 代码时,我可以使用 DirectoryEntry 列出我的站点和虚拟目录吗?我有在 IIS Express 下设置虚拟目录的示例,所以我想我已经介绍过了。现在我想列出它们以确保它们存在。

有人知道如何在 C# 中做到这一点吗?我一直在尝试的只是一个小的 sn-p 导致 com 异常......

DirectoryEntry iisServer = new DirectoryEntry("IIS://localhost/W3SVC/1");
DirectoryEntry folderRoot = iisServer.Children.Find("Root", "/");
var children = folderRoot.Children;

【问题讨论】:

  • @DJKRAZE:OP 说 COM 异常。
  • @leppie 我发布了和他尝试的示例我没有看到他有或正在获得 COM 异常,因为我习惯于看到大写的“COM”.. 哈哈,谢谢

标签: c# iis-express


【解决方案1】:

你可以试试这样的

void ListVirtualDirectories(string serverName, int siteId)
{            
       DirectoryEntry iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/" + siteId + "/ROOT");

       foreach (DirectoryEntry webDir in iisServer.Children)
       {
           if (webDir.SchemaClassName.Equals("IIsWebVirtualDir"))
               Console.WriteLine("Found virtual directory {0}", webDir.Name);
       }
}

【讨论】:

  • System.Runtime.InteropServices.COMException: 未知错误 (0x80005000) 此示例代码仍然返回此错误。
  • 尝试迭代iisServer.Children时返回错误。
  • 这是 ActiveDirectory 中的权限错误 google the error (0x80005000)
猜你喜欢
  • 2020-04-19
  • 2010-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-29
  • 1970-01-01
相关资源
最近更新 更多