1. 程式人生 > >使用C#設定IIS站點執行的.Net版本示例

使用C#設定IIS站點執行的.Net版本示例

/**//// <summary>        /// 獲取伺服器IIS版本        /// </summary>        /// <param name="DomainName"></param>        /// <returns></returns>        public WebServerTypes GetIISServerType(string DomainName)        ...{            if ((SiteInfo.DomainName == null) || (SiteInfo.DomainName == "")) SiteInfo.DomainName = "LOCALHOST";            string path = "IIS://" + SiteInfo.DomainName + "/W3SVC/INFO";            DirectoryEntry entry = null;            try            ...{                entry = new DirectoryEntry(path);            }            catch            ...{                return WebServerTypes.Unknown;            }            int num = 5;            try            ...{                num = (int)entry.Properties["MajorIISVersionNumber"].Value;            }            catch            ...{                return WebServerTypes.IIS5;            }            switch (num)            ...{                case 6:                    return WebServerTypes.IIS6;                case 7:                    return WebServerTypes.IIS7;            }            return WebServerTypes.IIS6;        }