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.
The easiest way is to load up IIS Manager and click on the "Sites" folder. There should be a column called "ID" in the list shown in the Features View pane, and that's your Site ID.
The site name is a descriptive name which will appear in the IIS management interface. This name can be anything that allows you to determine at a glance what the site is.
As Carlos and others mentioned in the comments, it's better to use HostingEnvironment.SiteName
since GetSiteName
is not supposed to be used by users (According to the docs).
System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With