Get Azure WebApp/WebSite name at runtime

2019-06-17 18:11发布

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?

1条回答
家丑人穷心不美
2楼-- · 2019-06-17 18:49

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"]
查看更多
登录 后发表回答