/// <summary> /// Delete a website service /// </summary> /// <param name="name">the name of the website</param> 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, string appPool) { // validate root path if (System.IO.Directory.Exists(rootPath) == false) { throw new DirNotFoundException(rootPath); } // get directory service DirectoryEntry Services = new DirectoryEntry("IIS://localhost/W3SVC"); // get server name (index) 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 // create website 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 + ":"); // create ROOT for website DirectoryEntry root = Server.Children.Add("ROOT", IISWebVirturalDir.IIsVirtualDir); root.Properties["path"].Clear(); root.Properties["path"].Add(rootPath); // create application if (string.IsNullOrEmpty(appPool)) { root.Invoke("appCreate", 0); } else { // use application pool 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); // commit changes root.CommitChanges(); Server.CommitChanges(); // return the newly created website IISWebsite website = new IISWebsite(Server); return(website); }
/// <summary> /// create a new website /// </summary> /// <param name="name">website name</param> /// <param name="port">website port</param> /// <param name="rootPath">root path</param> /// <returns></returns> public static IISWebsite CreateWebsite(string name, int port, string rootPath) { return(IISWebsite.CreateWebsite(name, port, rootPath, null)); }