« Previous Next »

Thread: Get list of all sites using ASP.NET running on IIS6

Last post 10-09-2007 5:05 PM by mvolo. 1 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (2 items)

Sort Posts:

  • 10-09-2007, 1:03 PM

    Get list of all sites using ASP.NET running on IIS6

    Hi,

    I'm trying to get a list of all sites running on our development server. After looking at a few examples online, I've come up with this:


    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.DirectoryServices;

    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

            DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/W3SVC");

             RecursiveDump(W3SVC.Children);
           
        }

        public void RecursiveDump(DirectoryEntries site)
        {

            foreach (DirectoryEntry s in site)
            {

                Response.Write(s.Path + "<br />");

                int notUsed;

                if (Int32.TryParse(s.Name, out notUsed))
                {
                    Response.Write(s.Properties["ServerComment"].Value + "<br />");
                }

                if (s.Children != null)
                {
                    RecursiveDump(s.Children);
                }

            }

        }

    }

     

    This gives the output:

    IIS://localhost/W3SVC/1
    Default Web Site
    IIS://localhost/W3SVC/1/Filters
    IIS://localhost/W3SVC/1/IIsCertMapper
    IIS://localhost/W3SVC/1/ROOT
    IIS://localhost/W3SVC/1/ROOT/aspnet_client
    IIS://localhost/W3SVC/AppPools
    IIS://localhost/W3SVC/Filters
    IIS://localhost/W3SVC/Filters/ASP.NET_2.0.50727.0
    IIS://localhost/W3SVC/Filters/Compression
    IIS://localhost/W3SVC/Filters/Compression/deflate
    IIS://localhost/W3SVC/Filters/Compression/gzip
    IIS://localhost/W3SVC/Filters/Compression/Parameters

    ...which is interesting but not really what I'm after. It's listed one of the sites, Default Web Site, but not any others. There are two more sites (not virtual directories) on the server.

    Thanks,

    Tom
     

  • 10-09-2007, 5:05 PM In reply to

    • mvolo
    • Top 25 Contributor
    • Joined on 09-17-2003, 1:48 PM
    • Philadelphia, PA
    • Posts 584

    Re: Get list of all sites using ASP.NET running on IIS6

    Tom,

    Each site node under W3SVC will be in the form of a siteid, like "IIS://localhost/W3SVC/1".  Also, each of the site nodes will have the KeyType = IIsWebServer.

    You do not need to do this recursively, since all site nodes are directly under the W3SVC node.  Also, there are other nodes under there that are not site nodes, that will not be numeric AND will not have KeyType = IIsWebServer, so you can eliminate those.

    If you want to enumerate applications under each site, then you need to get recursive for each of the site nodes, and look for the "AppIsolated" property having the value of "2" for each node that is marked as an application.

    Thanks,

    Mike

    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (2 items)