What is the best way to determine if my web application code is running in a Azure web role (or emulator)?
I need to configure a dependency injection container and do not want to take a dependency on any Azure specific assemblies unless I'm running in Azure.
Both answers to this question require referencing Azure specific assemblies which I'd like to prevent for my on-premise scenario.
Update: I'm really looking for something in the runtime environment that I can query from my web application code.
Best How To :
You could do this with via a
ServiceConfiguration.cscfg setting that you only set in the specific environments that you want.
Add a parameter, for example:
<Setting name="PaaS" value="true" />
Then, at application startup, get the value:
public bool IsPaaS
var res = false;
var val = CloudConfigurationManager.GetSetting("PaaS") ?? "false";
Boolean.TryParse(val, out res);
CloudConfigurationManager.GetSetting will fall back if there is no
cscfg setting present, and check the
Set this in the
WebRole, but not in the
web.config when running under local IIS to get the behavior you are looking for.