public static bool DeleteWebsite(string name) { IISWebsite website = IISWebsite.OpenWebsite(name); if (website == null) { return(false); } website.websiteEntry.DeleteTree(); return(true); }
public static IISWebsite CreateWebsite(string name, int port, string rootPath) { return(IISWebsite.CreateWebsite(name, port, rootPath, null)); }
public static IISWebsite CreateWebsite(string name, int port, string rootPath, string appPool) { if (global::System.IO.Directory.Exists(rootPath) == false) { throw new DirNotFoundException(rootPath); } DirectoryEntry Services = new DirectoryEntry("IIS://localhost/W3SVC"); int index = 0; foreach (DirectoryEntry server in Services.Children) { if (server.SchemaClassName == "IIsWebServer") { if (server.Properties["ServerComment"][0].ToString() == name) { throw new Exception("website:" + name + " already exsit."); } if (Convert.ToInt32(server.Name) > index) { index = Convert.ToInt32(server.Name); } } } index++; // new index created DirectoryEntry Server = Services.Children.Add(index.ToString(), IIsWebServer); Server.Properties["ServerComment"].Clear(); Server.Properties["ServerComment"].Add(name); Server.Properties["Serverbindings"].Clear(); Server.Properties["Serverbindings"].Add(":" + port + ":"); DirectoryEntry root = Server.Children.Add("ROOT", IISWebVirturalDir.IIsVirtualDir); root.Properties["path"].Clear(); root.Properties["path"].Add(rootPath); if (string.IsNullOrEmpty(appPool)) { root.Invoke("appCreate", 0); } else { root.Invoke("appCreate3", 0, appPool, true); } root.Properties["AppFriendlyName"].Clear(); root.Properties["AppIsolated"].Clear(); root.Properties["AccessFlags"].Clear(); root.Properties["FrontPageWeb"].Clear(); root.Properties["AppFriendlyName"].Add(root.Name); root.Properties["AppIsolated"].Add(2); root.Properties["AccessFlags"].Add(513); root.Properties["FrontPageWeb"].Add(1); root.CommitChanges(); Server.CommitChanges(); IISWebsite website = new IISWebsite(Server); return(website); }
public static IISWebsite CreateWebsite(string name, int port, string rootPath, string appPool) { if (global::System.IO.Directory.Exists(rootPath) == false) { throw new DirNotFoundException(rootPath); } DirectoryEntry Services = new DirectoryEntry("IIS://localhost/W3SVC"); int index = 0; foreach (DirectoryEntry server in Services.Children) { if (server.SchemaClassName == "IIsWebServer") { if (server.Properties["ServerComment"][0].ToString() == name) { throw new Exception("website:" + name + " already exsit."); } if (Convert.ToInt32(server.Name) > index) { index = Convert.ToInt32(server.Name); } } } index++; // new index created DirectoryEntry Server = Services.Children.Add(index.ToString(), IIsWebServer); Server.Properties["ServerComment"].Clear(); Server.Properties["ServerComment"].Add(name); Server.Properties["Serverbindings"].Clear(); Server.Properties["Serverbindings"].Add(":" + port + ":"); DirectoryEntry root = Server.Children.Add("ROOT", IISWebVirturalDir.IIsVirtualDir); root.Properties["path"].Clear(); root.Properties["path"].Add(rootPath); if (string.IsNullOrEmpty(appPool)) { root.Invoke("appCreate", 0); } else { root.Invoke("appCreate3", 0, appPool, true); } root.Properties["AppFriendlyName"].Clear(); root.Properties["AppIsolated"].Clear(); root.Properties["AccessFlags"].Clear(); root.Properties["FrontPageWeb"].Clear(); root.Properties["AppFriendlyName"].Add(root.Name); root.Properties["AppIsolated"].Add(2); root.Properties["AccessFlags"].Add(513); root.Properties["FrontPageWeb"].Add(1); root.CommitChanges(); Server.CommitChanges(); IISWebsite website = new IISWebsite(Server); return website; }