问题描述
我知道我们可以使用 RoleEnvironment.IsAvailable
来检查代码是否在 Web/Worker 角色中运行.Azure 网站怎么样?
I knew that we can use RoleEnvironment.IsAvailable
to check if code is running in Web/Worker Role. How about Azure Websites?
我尝试了上面的 RoleEnvironment 代码,但它总是返回 false.我需要在 Application_Start
中运行一些配置代码,所以我不能依赖请求的东西.
I tried the above RoleEnvironment code but it always returns false. I need to run some configuration code in Application_Start
so I cannot depend on the request stuff.
感谢任何帮助.
推荐答案
这实际上很容易,只需检查此环境变量是否存在:WEBSITE_SITE_NAME
.
This is actually very easy simply check for existence of this environment variable: WEBSITE_SITE_NAME
.
!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"))
此内容将是您网站的名称.
The content for this will be the name of your site.
要查看站点下的更多环境变量,请访问以下链接:https://{sitename}.scm.azurewebsites.net/Env
To see more environment variable that you have under your site go to the following link: https://{sitename}.scm.azurewebsites.net/Env
这篇关于如何检查代码是否在 Azure 网站上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!