Determine if a class is running in Azure and if it is actually in the cloud vs. the emulator
We needed to determine if a class was running in Azure and if so whether it was actually in the cloud or being emulated locally.
Turns out this is very simple to do, just add a reference to:
Microsoft.WindowsAzure.ServiceRuntime
And then use these two static booleans, notice the try/catch blocks, 32 bit processes throw an error here, so reporting false in the catch remedies that.
public static bool InAzureEnvironment
{
get
{
try
{
return RoleEnvironment.IsAvailable;
}
catch { return false; }
}
}
public static bool InCloud
{
get
{
try
{
return InAzureEnvironment && !RoleEnvironment.IsEmulated;
}
catch { return false; }
}
}
Written by Mike Olsen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#.net
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#