在运行时获取Azure的Web应用程序/网站名称 [英] Get Azure WebApp/WebSite name at runtime

查看:128
本文介绍了在运行时获取Azure的Web应用程序/网站名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有像myapp.azurewebsites.net名称的Web应用程序,也有一个名为myapp-failover.azurewebsites.net故障切换。它采用了DNS和流量管理器,以便该网站实际上是www.mysite.com。

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.

我wan't检查,如果我的主网站或故障切换和最简单的方法上运行的是,如果可以检查myapp.azurewebsites.net名称。是否有可能得到这个?

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?

推荐答案

有一些环境变量,这将帮助你确定哪些机实例您正在运行以及哪些区域要在运行。以最简单的方式识别它们是从 https://myapp.scm.azurewebsites.net/Env 登录到捻控制台网站(这使用OAuth所以如果你已经登录到门户网站,你会直接通过)。

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

您将看到:

REGION_NAME - 该网站是在结果的托管区域的名称
WEBSITE_INSTANCE_ID - ARR的亲和力对Cookie的网站结果
WEBSITE_SITE_NAME - 网站的名称(域名preFIX)结果
WEBSITE_HOSTNAME - 主机名的网站

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

以及更多!

修改

如果你正在使用的Node.js或者PHP可以按照以下<一个href=\"http://blog.syntaxc4.net/post/2012/07/26/accessing-app-settings-configured-in-microsoft-azure-web-sites-using-php-and-node-js.aspx\">instructions这里通过相应的语言环境变量检索机制访问这些变量。

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.

如果您正在使用.NET,你可以把他们喜欢的应用设置:

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

ConfigurationManager.AppSettings["Key"]

这篇关于在运行时获取Azure的Web应用程序/网站名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆