10 March, 2009
0 Comments
0 categories
/// <summary> /// List all properties of a IIS website /// </summary> /// <param name="serverName">Name of the IIS server e.g. localhost</param> /// <param name="websiteName">Name of the website e.g. test</param> public void ListWebsiteProperties(string serverName, string websiteName) { if (string.IsNullOrEmpty(serverName)) { throw new Exception("Parameter [serverName] can't be null or empty"); } if (string.IsNullOrEmpty(websiteName)) { throw new Exception("Parameter [websiteName] can't be null or empty"); } DirectoryEntry w3svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", serverName)); foreach (DirectoryEntry site in w3svc.Children) { foreach (PropertyValueCollection property in site.Properties) { Console.WriteLine(string.Format("{0}[{1}]", property.PropertyName, property.Value)); } if (site.Properties["ServerComment"] != null) { if (site.Properties["ServerComment"].Value != null) { if (string.Compare(site.Properties["ServerComment"].Value.ToString(), websiteName, false) == 0) { foreach (DirectoryEntry child in site.Children) { foreach (PropertyValueCollection property in child.Properties) { Console.WriteLine(string.Format("{0}[{1}]", property.PropertyName, property.Value)); } } } } } } }