我有一个应用程序可以远程停止/重新启动应用程序池/站点并检查应用程序池/站点的状态。目前,这些是使用 DirectoryEntry 类管理的,例如
private DirectoryEntry FindSite(int nPort)
{
using (var sites = new DirectoryEntry(string.Format(m_adSitesPath,m_RemoteServerName)))
{
sites.RefreshCache();
foreach (DirectoryEntry de in sites.Children)
{
de.RefreshCache();
if (de.SchemaClassName == "IIsWebServer")
{
string port = GetNullableDirMultiValuePart(de, "ServerBindings", 0, 1);
if (nPort == int.Parse(port))
{
return de;
}
}
}
}
return null;
}
这种方法在任何运行 IIS 8 的服务器上都失败了,在另一个问题上,有人建议我应该开始考虑使用 Microsoft.Web.Administrator 类。有人可以指点我正确的方向,以便我使用 Microsoft.Web.Administrator 命名空间按端口获取站点列表吗?