I've an application that remotely stops/restarts app pools/sites and checks the status of the app pools/sites as well. At present these are managed using the DirectoryEntry class e.g.
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;
}
this method is failing on any servers running IIS 8, on another question it was suggested I should start looking at using the Microsoft.Web.Administrator classes. Could someone please point me in the right direction so I get a list of sites by Port using the Microsoft.Web.Administrator namespace?