Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Azure WebApp/WebSite name at runtime

I have a WebApp with a name like myapp.azurewebsites.net and also have a failover with the name myapp-failover.azurewebsites.net. It uses a DNS and Traffic Manager so the site is actually www.mysite.com.

I wan't to check if I am running on the main site or failover and the easiest way would be to check the myapp.azurewebsites.net name if possible. Is it possible to get this?

like image 686
Craig Avatar asked Aug 09 '15 04:08

Craig


1 Answers

There are a number of Environment Variables that will help you identify which machine instance you are running on as well as which region you are running in. The easiest way to identify them is to log into the Kudu Console for the site from https://myapp.scm.azurewebsites.net/Env (this uses OAuth so if you're already logged into the portal, you'll pass right through).

You will see:

REGION_NAME - The name of the region the site is hosted in
WEBSITE_INSTANCE_ID - The ARR Affinity Cookie for the site
WEBSITE_SITE_NAME - the site name (domain prefix)
WEBSITE_HOSTNAME - the hostname for the site

and much much more!

EDIT

If you are using Node.js or PHP you can follow these instructions here to access those variables via the respective language Environment Variable retrieval mechanism.

If you're using .NET, you can treat them like an App Setting:

ConfigurationManager.AppSettings["Key"]
like image 139
cory-fowler Avatar answered Sep 22 '22 00:09

cory-fowler