20

I have an asp.net mvc app that is built to run as standard web app in iis or in the cloud.

I need to be able to determine if the app is being hosted in azure(dev fabric or cloud) or if it is being run as standard web app under iis.

How can I tell if it is running in cloud?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
longday
  • 4,075
  • 4
  • 28
  • 35

2 Answers2

43

Think I found it:

Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable

Thanks

@Wheat: Thanks for such a quick response, makes stackoverflow.com a great resource.

David Pfeffer
  • 38,869
  • 30
  • 127
  • 202
longday
  • 4,075
  • 4
  • 28
  • 35
  • 2
    Incidentally RoleEnvironment.IsAvailable only works in a 64-bit environment. Some of our servers are still 32-bit, so I surround it with a try ... catch ... and return false on an exception. – Steve Owen Jan 28 '13 at 10:28
  • does Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable work for being able to determine if the asp.net app is running on an Azure VM? – cResults Apr 25 '22 at 15:12
1

Could you use the StorageAccountInfo class?:

In your StorageAccountInfo object, the property "usePathStyleUris" is false when you are pointing to cloud storage and true when you are pointing to Development Storage locally.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541