Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get IIS Application Name in .NET App

Tags:

c#

.net

iis

I am currently using the following code:

<center>Application Name: <%=HostingEnvironment.ApplicationID %></center>

Which outputs:

Application Name: /LM/W3SVC/1/Root/AppName

"AppName" is the value I want and I'm wondering whether there is another method that will simply return it without having to do string magic to remove the rest of the path.

Thanks!

like image 973
xeon Avatar asked Jun 28 '12 18:06

xeon


Video Answer


1 Answers

To reiterate, based on the comment thread - ApplicationHost.GetSiteName() is not intended to be used in code (see msdn.microsoft.com):

IApplicationHost.GetSiteName Method ()

This API supports the product infrastructure and is not intended to be used directly from your code.

Instead use

System.Web.Hosting.HostingEnvironment.SiteName;

Documentation at MSDN

like image 173
EvilDr Avatar answered Oct 05 '22 20:10

EvilDr