DCSIMG
Reading Web Sites Status on IIS with .Net - Shai Raiten

Shai Raiten

 Subscribe

Reading Web Sites Status on IIS with .Net

Reading Web Sites Status on IIS with .Net

This is some ability I needed for one of my tools.

 

Using DirectoryEntry to get information about IIS Web Sites and AppPools.

 

Code Simple:

 

public WebSiteEntry[] GetWebSites()

    {

      string Path = "IIS://" + this.DomainName + "/W3SVC";

      DirectoryEntry root = null;

      try

      {

        root = new DirectoryEntry(Path);

      }

      catch

      {

        MessageBox.Show("Couldn't access root node", "Error",  MessageBoxButton.OK, MessageBoxImage.Information);

        return null;

      }

      if (root == null)

      {

        MessageBox.Show("Couldn't access root node", "Error", MessageBoxButton.OK, MessageBoxImage.Information);       

        return null;

      }

 

      ArrayList WebSiteList = new ArrayList();

      foreach (DirectoryEntry Entry in root.Children)

      {

       PropertyCollection Properties = Entry.Properties;

       try

       {

        WebSiteEntry Site = new WebSiteEntry();

        Site.SiteName = (string)Properties["ServerComment"].Value;

        Site.State = (string)Properties["ServerState"].Value.ToString();

        <!-- 2 – Start , 4 – Stoped, 6 – Paused -->

        WebSiteList.Add(Site);

       }

       catch { ; }

      }

      root.Close();

      return (WebSiteEntry[])WebSiteList.ToArray(typeof(WebSiteEntry));

    }

 

    public class WebSiteEntry

    {

      public string SiteName = "";

      public string State = "";

    }

 

Comments

autocarsinsurance.net » Blog Archive » Reading Web Sites Status on IIS with .Net said:

Pingback from  autocarsinsurance.net  &raquo; Blog Archive   &raquo; Reading Web Sites Status on IIS with .Net

# November 3, 2008 5:19 AM

Shai Raiten said:

Creating Virtual Web Sites on IIS with .Net My last post on Reading Web Sites Status on IIS with .Net

# November 23, 2008 3:04 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# November 29, 2008 4:28 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: