How can I determine if I am running locally on my PC or on the cloud?

前端 未结 4 2045
你的背包
你的背包 2020-12-31 08:37

Using MVC3 and I\'d like to determine if I am running locally or deployed to the cloud?

4条回答
  •  [愿得一人]
    2020-12-31 09:03

    RoleEnvironment.IsAvailable tells you if you're running in Windows Azure, but it doesn't differentiate between the real Windows Azure and the local development simulator.

    I wrote a blog post that shows a trick to figure out whether you're running in real vs. simulated Windows Azure, when RoleEnvironment.IsAvailable == true - hopefully that provides what you're looking for.

    EDIT: In case you want the down-n-dirty code I describe in the abovementioned post, without any explanation of why the technique works:

    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
        }
    

    EDIT 2: My answer is a bit outdated. There's now RoleEnvironment.IsEmulated, which is much more straightforward to use. MSDN documentation is here

提交回复
热议问题