Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get IIS site name from for an ASP.NET website

Tags:

c#

asp.net

iis

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.

like image 326
Søren Spelling Lund Avatar asked Oct 31 '09 16:10

Søren Spelling Lund


People also ask

How do I find my IIS website name?

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.

What is IIS site name?

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.


1 Answers

Update

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).

Old Solution

System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName(); 
like image 55
Mehdi Golchin Avatar answered Sep 19 '22 15:09

Mehdi Golchin