C# – Get IIS site name from for an ASP.NET website

asp.netciis

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 site but the actual name given to the site in IIS.

I need to be able to do it reliably for IIS6 and 7.

To be clear I'm talking about the given name in IIS, not the domain name and not the virtual directory path.

Best Answer

System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();