Example #1
0
        /// <summary>
        /// Gets a list of websites on an IIS Server
        /// </summary>
        /// <param name="server">A list of IISWebsite information objects</param>
        /// <returns>list of websites on an IIS Server in the form of IIsWebsiteInfo objects</returns>
        public static List <IIsWebsiteInfo> GetWebsitesOnIISServer(string server)
        {
            List <IIsWebsiteInfo> webSites = new List <IIsWebsiteInfo>();
            DirectoryEntry        W3SVC    = new DirectoryEntry(string.Format("IIS://{0}/W3SVC", server));

            foreach (DirectoryEntry Site in W3SVC.Children)
            {
                if (0 == string.Compare(Site.SchemaClassName, "IIsWebServer"))
                {
                    IIsWebsiteInfo webSite = new IIsWebsiteInfo();
                    webSite.WebsiteID = Site.Name;
                    string serverComment = Convert.ToString(Site.Properties["ServerComment"].Value);
                    if (!string.IsNullOrEmpty(serverComment))
                    {
                        webSite.FriendlyName = serverComment;
                    }
                    List <string>           ports       = new List <string>();
                    PropertyValueCollection bindings    = Site.Properties["ServerBindings"];
                    PropertyValueCollection bindingsSSL = Site.Properties["SecureBindings"];
                    if (bindings != null)
                    {
                        foreach (object binding in bindings)
                        {
                            ports.Add((string)binding);
                        }
                    }
                    if (bindingsSSL != null)
                    {
                        webSite.UsingSSL = true;
                        foreach (object binding in bindingsSSL)
                        {
                            ports.Add((string)binding);
                        }
                    }
                    webSite.Ports = new List <string>();
                    foreach (string port in ports)
                    {
                        webSite.Ports.Add(port);
                    }
                    webSites.Add(webSite);
                }
            }
            return(webSites);
        }
 /// <summary>
 /// Gets a list of websites on an IIS Server
 /// </summary>
 /// <param name="server">A list of IISWebsite information objects</param>
 /// <returns>list of websites on an IIS Server in the form of IIsWebsiteInfo objects</returns>
 public static List<IIsWebsiteInfo> GetWebsitesOnIISServer(string server)
 {
     List<IIsWebsiteInfo> webSites = new List<IIsWebsiteInfo>();
     DirectoryEntry W3SVC = new DirectoryEntry(string.Format("IIS://{0}/W3SVC", server));
     foreach (DirectoryEntry Site in W3SVC.Children)
     {
         if (0 == string.Compare(Site.SchemaClassName, "IIsWebServer"))
         {
             IIsWebsiteInfo webSite = new IIsWebsiteInfo();
             webSite.WebsiteID = Site.Name;
             string serverComment = Convert.ToString(Site.Properties["ServerComment"].Value);
             if (!string.IsNullOrEmpty(serverComment))
             {
                 webSite.FriendlyName = serverComment;
             }
             List<string> ports = new List<string>();                    
             PropertyValueCollection bindings = Site.Properties["ServerBindings"];
             PropertyValueCollection bindingsSSL = Site.Properties["SecureBindings"];
             if (bindings != null)
             {
                 foreach (object binding in bindings)
                 {
                     ports.Add((string)binding);
                 }                        
             }
             if (bindingsSSL != null)
             {
                 webSite.UsingSSL = true;
                 foreach (object binding in bindingsSSL)
                 {
                     ports.Add((string)binding);
                 }
             }
             webSite.Ports = new List<string>();
             foreach (string port in ports)
             {
                 webSite.Ports.Add(port);
             }
             webSites.Add(webSite);
         }
     }
     return webSites;
 }