public void CreateWebServerTest() { IISManagement iisman = new IISManagement(); IISWebServer webServer = new IISWebServer(); webServer.ServerComment = "test"; IISManagement.CreateIISWebServer(webServer); Assert.AreEqual(true, IISManagement.ExistsIISWebServer("test")); }
private void btnAdd_Click(object sender, System.EventArgs e) { try { IISWebServer ws = iis.GetWebServer((string)Session["CurrentServerName"]); ws.CreateVirtualDirectory(txtVirtualDirectoryName.Text.Trim(), txtVirtualDirectoryRootPath.Text.Trim(), chkApplication.Checked); txtVirtualDirectoryName.Text = ""; txtVirtualDirectoryRootPath.Text = ""; chkApplication.Checked = false; } catch (Exception ex) { divError.InnerText = "* Error during the operation : " + ex.InnerException.Message; divError.Visible = true; } }
/**/ /**/ /**/ /// <summary> /// /// </summary> public IISWebServer Parent = null; #endregion Fields #region Constructors /**/ /**/ /**/ /// <summary> /// /// </summary> /// <param name="Parent"></param> public IISWebVirtualDirCollection(IISWebServer Parent) { this.Parent = Parent; }
/// <summary> /// 创建站点 /// </summary> /// <param name="iisServer"></param> public static void CreateIISWebServer(IISWebServer iisServer) { if (iisServer.ServerComment.ToString() == "") throw (new Exception("IISWebServer的ServerComment不能为空!")); DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC"); DirectoryEntry Server; int i = 0; IEnumerator ie = Service.Children.GetEnumerator(); while (ie.MoveNext()) { Server = (DirectoryEntry)ie.Current; if (Server.SchemaClassName == "IIsWebServer") { if (Convert.ToInt32(Server.Name) > i) i = Convert.ToInt32(Server.Name); // if( Server.Properties["Serverbindings"][0].ToString() == ":" + iisServer.Port + ":" ) // { // Server.Invoke("stop",new object[0]); // } } } i++; try { iisServer.index = i; Server = Service.Children.Add(i.ToString(), "IIsWebServer"); Server.Properties["ServerComment"][0] = iisServer.ServerComment; Server.Properties["Serverbindings"].Add(":" + iisServer.Port + ":"); Server.Properties["AccessScript"][0] = iisServer.AccessScript; Server.Properties["AccessRead"][0] = iisServer.AccessRead; Server.Properties["EnableDirBrowsing"][0] = iisServer.EnableDirBrowsing; Server.Properties["DefaultDoc"][0] = iisServer.DefaultDoc; Server.Properties["EnableDefaultDoc"][0] = iisServer.EnableDefaultDoc; DirectoryEntry root = Server.Children.Add("Root", "IIsWebVirtualDir"); root.Properties["path"][0] = iisServer.Path; Service.CommitChanges(); Server.CommitChanges(); root.CommitChanges(); root.Invoke("AppCreate2", new object[1] { 2 }); //Server.Invoke("start",new object[0]); } catch (Exception es) { throw (es); } }
internal void Add_(IISWebServer WebServer) { this.List.Add(WebServer); }
/// <summary> /// /// </summary> /// <param name="WebServer"></param> public void Remove(IISWebServer WebServer) { for (int i = 0; i < this.List.Count; i++) { if ((IISWebServer)this.List[i] == WebServer) { this.List.RemoveAt(i); return; } } IISManagement.RemoveIISWebServer(WebServer.index); }
/// <summary> /// /// </summary> /// <param name="WebServers"></param> public void AddRange(IISWebServer[] WebServers) { for (int i = 0; i <= WebServers.GetUpperBound(0); i++) { Add(WebServers[i]); } }
/// <summary> /// /// </summary> /// <param name="WebServer"></param> public void Add(IISWebServer WebServer) { try { this.List.Add(WebServer); IISManagement.CreateIISWebServer(WebServer); } catch { throw (new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入")); } }
private void start() { DirectoryEntry Service = new DirectoryEntry("IIS://" + Machinename + "/W3SVC"); DirectoryEntry Server; DirectoryEntry Root = null; DirectoryEntry VirDir; IEnumerator ie = Service.Children.GetEnumerator(); IEnumerator ieRoot; IISWebServer item; IISWebVirtualDir item_virdir; bool finded = false; while (ie.MoveNext()) { Server = (DirectoryEntry)ie.Current; if (Server.SchemaClassName == "IIsWebServer") { item = new IISWebServer(); item.index = Convert.ToInt32(Server.Name); item.ServerComment = (string)Server.Properties["ServerComment"][0]; item.AccessRead = (bool)Server.Properties["AccessRead"][0]; item.AccessScript = (bool)Server.Properties["AccessScript"][0]; item.DefaultDoc = (string)Server.Properties["DefaultDoc"][0]; item.EnableDefaultDoc = (bool)Server.Properties["EnableDefaultDoc"][0]; item.EnableDirBrowsing = (bool)Server.Properties["EnableDirBrowsing"][0]; ieRoot = Server.Children.GetEnumerator(); while (ieRoot.MoveNext()) { Root = (DirectoryEntry)ieRoot.Current; if (Root.SchemaClassName == "IIsWebVirtualDir") { finded = true; break; } } if (finded) { item.Path = Root.Properties["path"][0].ToString(); } item.Port = Convert.ToInt32(((string)Server.Properties["Serverbindings"][0]).Substring(1, ((string)Server.Properties["Serverbindings"][0]).Length - 2)); this.WebServers.Add_(item); ieRoot = Root.Children.GetEnumerator(); while (ieRoot.MoveNext()) { VirDir = (DirectoryEntry)ieRoot.Current; if (VirDir.SchemaClassName != "IIsWebVirtualDir" && VirDir.SchemaClassName != "IIsWebDirectory") continue; item_virdir = new IISWebVirtualDir(item.ServerComment); item_virdir.Name = VirDir.Name; item_virdir.AccessRead = (bool)VirDir.Properties["AccessRead"][0]; item_virdir.AccessScript = (bool)VirDir.Properties["AccessScript"][0]; item_virdir.DefaultDoc = (string)VirDir.Properties["DefaultDoc"][0]; item_virdir.EnableDefaultDoc = (bool)VirDir.Properties["EnableDefaultDoc"][0]; if (VirDir.SchemaClassName == "IIsWebVirtualDir") { item_virdir.Path = (string)VirDir.Properties["Path"][0]; } else if (VirDir.SchemaClassName == "IIsWebDirectory") { item_virdir.Path = Root.Properties["Path"][0] + "\\" + VirDir.Name; } item.WebVirtualDirs.Add_(item_virdir); } } } }
/// <summary> /// 修改与给定的IISWebServer具有相同网站说明的站点配置 /// </summary> /// <param name="iisServer">给定的IISWebServer</param> public static void EditIISWebServer(IISWebServer iisServer) { if (iisServer.index == -1) throw (new Exception("找不到给定的站点!")); DirectoryEntry Service = new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC"); DirectoryEntry Server; IEnumerator ie = Service.Children.GetEnumerator(); while (ie.MoveNext()) { Server = (DirectoryEntry)ie.Current; if (Server.SchemaClassName == "IIsWebServer") { if (Server.Properties["Serverbindings"][0].ToString() == ":" + iisServer.Port + ":") { Server.Invoke("stop", new object[0]); } } } Server = returnIISWebserver(iisServer.index); if (Server == null) { throw (new Exception("找不到给定的站点!")); } try { Server.Properties["ServerComment"][0] = iisServer.ServerComment; Server.Properties["Serverbindings"][0] = ":" + iisServer.Port + ":"; Server.Properties["AccessScript"][0] = iisServer.AccessScript; Server.Properties["AccessRead"][0] = iisServer.AccessRead; Server.Properties["EnableDirBrowsing"][0] = iisServer.EnableDirBrowsing; Server.Properties["DefaultDoc"][0] = iisServer.DefaultDoc; Server.Properties["EnableDefaultDoc"][0] = iisServer.EnableDefaultDoc; DirectoryEntry root = getRoot(Server); Server.CommitChanges(); if (root != null) { root.Properties["path"][0] = iisServer.Path; root.CommitChanges(); } Server.Invoke("start", new object[0]); } catch (Exception es) { throw (es); } }