Tuesday, February 15, 2005

Diplay IIS hosted Site Names in C#

I have been working on a project module which will interact with IIS and will display hosted sites or virtual directories,so far i have done this by using ADSII ,the code is very raw,i will submit final snippet once it`s done..this code will display website names hosted on IIS


try
{
const string WebServerSchema = "IIsWebServer"; // Case Sensitive
string ServerName = "SIDDIQI";
DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + ServerName + "/w3svc", "Domain/UserCode", "Password");
foreach (DirectoryEntry Site in W3SVC.Children)
{

if (Site.SchemaClassName == WebServerSchema)
{
//Console.WriteLine(Site.Name + " - " + Site.Properties["ServerComment"].Value.ToString());
}
}
}
// Catch any errors
catch (Exception e)
{
Console.WriteLine("Error: " + e.ToString());
}