Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Parent"></param>
 public IISWebVirtualDirCollection(IISWebServer Parent)
 {
     this.Parent = Parent;
 }
Exemplo n.º 2
0
 internal void Add_(IISWebServer WebServer)
 {
     this.List.Add(WebServer);
 }
Exemplo n.º 3
0
        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.ToInt16(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();
                    }


                    if (string.IsNullOrEmpty(Convert.ToString(Server.Properties["Serverbindings"].Value)))
                    {
                        continue;
                    }
                    item.Port = Convert.ToInt16(Server.Properties["Serverbindings"][0].ToString().Split(':')[1]);
                    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);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 创建站点
        /// </summary>
        /// <param name="iisServer"></param>
        public static void CreateIISWebServer(IISWebServer iisServer)
        {
            if (true == ExistsIISWebServer(iisServer.Port))
            {
                throw new Exception("指定的端口号不可用,原因可能是其他站点或应用程序占用!");
            }

            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.ToInt16(Server.Name) > i)
                    {
                        i = Convert.ToInt16(Server.Name);
                    }

                    Server.Invoke("start", 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;


                root.Invoke("AppCreate", false);


                //CreateAppPool(iisServer.ServerComment);
                //AssignAppPool(root,iisServer.ServerComment);

                Service.CommitChanges();
                Server.CommitChanges();
                root.CommitChanges();

                Server.Invoke("start", new object[0]);
            }
            catch (Exception es)
            {
                throw(es);
            }
        }