10 March, 2009
0 Comments
0 categories
/// <summary> /// Get website id on websitename /// </summary> /// <param name="serverName">Name of the IIS server e.g. localhost</param> /// <param name="websiteName">Name of the website e.g. test</param> /// <returns> /// Less the 0, site does not exist /// Id of the existing site /// </returns> public int GetWebSiteId(string serverName, string websiteName) { int result = -1; DirectoryEntry w3svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", serverName)); foreach (DirectoryEntry site in w3svc.Children) { if (site.Properties["ServerComment"] != null) { if (site.Properties["ServerComment"].Value != null) { if (string.Compare(site.Properties["ServerComment"].Value.ToString(), websiteName,
false) == 0) { result = site.Name; break; } } } } return result; }
Hi, cool post. I have been wondering about this topic,so thanks for writing.