Get Azure WebApp/WebSite name at runtime

南楼画角 提交于 2019-12-10 13:11:58

问题


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:


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"]


来源:https://stackoverflow.com/questions/31900883/get-azure-webapp-website-name-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!