Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <IISInfo> SiteInfos()
        {
            var    iisManager = new ServerManager();
            var    iisInfos   = new ObservableCollection <IISInfo>();
            string operation  = string.Empty;
            Func <string, string> serverstate = (state) =>
            {
                string stateinfo = string.Empty;
                switch (state)
                {
                case "Started":
                    stateinfo = "运行中";
                    operation = "停止";
                    break;

                case "Stopped":
                    stateinfo = "未运行";
                    operation = "启动";
                    break;
                }
                return(stateinfo);
            };

            foreach (var site in iisManager.Sites)
            {
                var iisInfo = new IISInfo()
                {
                    SiteName = site.Name, RunState = serverstate(site.State.ToString()), Operation = operation
                };
                iisInfo.IisCmd = new CommandObject(iisInfo.OperationCommand);
                iisInfos.Add(iisInfo);
            }
            return(iisInfos);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取站点名
        /// </summary>
        public static List <IISInfo> GetServerBindings()
        {
            var iisList = new List <IISInfo>();
            var entPath = String.Format("IIS://{0}/w3svc", HostName);
            var ent     = new DirectoryEntry(entPath);

            foreach (DirectoryEntry child in ent.Children)
            {
                if (child.SchemaClassName.Equals("IIsWebServer", StringComparison.OrdinalIgnoreCase))
                {
                    if (child.Properties["ServerBindings"].Value != null)
                    {
                        object objectArr = child.Properties["ServerBindings"].Value;
                        string serverBindingStr;
                        if (IsArray(objectArr))//如果有多个绑定站点时
                        {
                            var objectToArr = (object[])objectArr;
                            serverBindingStr = objectToArr[0].ToString();
                        }
                        else//只有一个绑定站点
                        {
                            serverBindingStr = child.Properties["ServerBindings"].Value.ToString();
                        }
                        var iisInfo = new IISInfo
                        {
                            DomainPort  = serverBindingStr,
                            SiteAppPool = child.Properties["AppPoolId"].Value.ToString()
                        };
                        iisList.Add(iisInfo);
                    }
                }
            }
            return(iisList);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="iisInfo"></param>
        public static bool CreateSite(IISInfo iisInfo)
        {
            bool flag = false;

            if (Int32.Parse(GetIIsVersion()) > 6)//IIS 7
            {
                var  serverManager = new ServerManager();
                Site site          = serverManager.Sites.Add(iisInfo.SiteName, iisInfo.BindingProtocol, iisInfo.DomainPort + iisInfo.SiteIpAdress, iisInfo.SitePhysicalPath);
                site.Applications["/"].ApplicationPoolName = iisInfo.SiteAppPool;
                site.ServerAutoStart = true;
                serverManager.CommitChanges();
                if (iisInfo.AppCollection.Count > 0)
                {
                    foreach (var variable in iisInfo.AppCollection)
                    {
                        CreateApplication(iisInfo.SiteName, variable.Substring(variable.LastIndexOf('\\') + 1), variable);
                    }
                }
                flag = true;
            }
            else//IIS 6及以下
            {
            }
            return(flag);
        }