public static bool ExistsInMetabase(string path) { using (DirectoryEntry root = OSDirectoryEntry.New(IISBasePath)) { foreach (DirectoryEntry entry in OSDirectoryEntry.GetChildren(root)) { using (entry) { if (entry.SchemaClassName == "IIsWebServer") { using (DirectoryEntry direntry = OSDirectoryEntry.New(IISBasePath + "/" + entry.Name + "/Root")) { if (direntry.Properties["Path"][0].ToString().Equals(path, StringComparison.InvariantCultureIgnoreCase)) { return(true); } foreach (DirectoryEntry espaceDir in OSDirectoryEntry.GetChildren(direntry)) { using (espaceDir) { if (espaceDir.SchemaClassName == "IIsWebVirtualDir") { if (espaceDir.Properties["Path"][0].ToString().Equals(path, StringComparison.InvariantCultureIgnoreCase)) { return(true); } } } } } } } } } return(false); }
private static int GetWebSiteId(string instanceName) { int id = 0; if (websiteIdGetterOverride != null) { id = websiteIdGetterOverride(instanceName); if (id > 0) { return(id); } else { id = 0; } } using (DirectoryEntry root = OSDirectoryEntry.New(IISBasePath)) { string site = GetWebSiteName(root, instanceName); foreach (DirectoryEntry entry in OSDirectoryEntry.GetChildren(root)) { using (entry) { if (entry.SchemaClassName == "IIsWebServer" && ((string)entry.InvokeGet("ServerComment")) == site) { id = Convert.ToInt32(entry.Name); } } } } return(id); }
private static string GetWebSiteName(DirectoryEntry root, string instanceName) { if (instanceName == Settings.GetDefaultValue(Settings.Configs.InstanceName)) { string defaultWebSiteName = Settings.Get(Settings.Configs.IIS_DefaultWebSiteName); if (defaultWebSiteName != Settings.GetDefaultValue(Settings.Configs.IIS_DefaultWebSiteName)) { return(defaultWebSiteName); } string firstchildname = ""; foreach (DirectoryEntry entry in OSDirectoryEntry.GetChildren(root)) { using (entry) { if (entry.SchemaClassName == "IIsWebServer") { if (firstchildname == "") { firstchildname = ((string)entry.InvokeGet("ServerComment")); } // Not sure if I should look for ID = 1... maybe sniffing the bindings would be better? if (entry.Name == "1") { return((string)entry.InvokeGet("ServerComment")); } } } } if (firstchildname != "") { return(firstchildname); // if no Id = 1 found, fallback to firstchild } else { return(Settings.GetDefaultValue(Settings.Configs.IIS_DefaultWebSiteName)); // This return is only used for creating a NEW web site } } else { return(instanceName); } }