使用 MVC3,我想确定我是在本地运行还是部署到云端?
最佳答案
RoleEnvironment.IsAvailable
告诉您是否在 Windows Azure 中运行,但它不会区分真正的 Windows Azure 和本地开发模拟器。
我写了一个blog post这展示了一个技巧,当 RoleEnvironment.IsAvailable == true
时,可以确定您是在真实 Windows Azure 中运行还是在模拟 Windows Azure 中运行 - 希望这能提供您正在寻找的内容。
编辑:如果您想要我在上述帖子中描述的简单的代码,而不解释该技术的工作原理:
private bool IsRunningInDevFabric()
{
// easiest check: try translate deployment ID into guid
Guid guidId;
if (Guid.TryParse(RoleEnvironment.DeploymentId, out guidId))
return false; // valid guid? We're in Azure Fabric
return true; // can't parse into guid? We're in Dev Fabric
}
编辑2:我的答案有点过时了。现在有 RoleEnvironment.IsEmulated
,它使用起来更加简单。 MSDN 文档是 here
关于azure - 如何确定我是在 PC 上本地运行还是在云端运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6160947/