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