In my ASP.NET web app I\'d like to look up the name it was given when it was created in IIS, which is unique to the server. I\'d not interested in the domain name for the web si
Here is a related post in retrieving the site Id.
Here some code that might work for you:
using System.DirectoryServices;
using System;
public class IISAdmin
{
public static void GetWebsiteID(string websiteName)
{
DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/w3svc");
foreach(DirectoryEntry de in w3svc.Children)
{
if(de.SchemaClassName == "IIsWebServer" && de.Properties["ServerComment"][0].ToString() == websiteName)
{
Console.Write(de.Name);
}
}
}
public static void Main()
{
GetWebsiteID("Default Web Site");
}
}
Here's the link to the original post.
I'm not sure if it will work on IIS7, but if you install the IIS6 compatibility components for IIS7 it should work.