Role Environment Variables in Full IIS Web Role and in HWC Web Role
When you will use the following code in Page_Load function of
default.aspx:
String sRootPath = Environment.GetEnvironmentVariable("RoleRoot");
You will see different results depend on Full IIS Web Role
and HWC as below:
Full IIS Web Role - sRootPath
= NULL
HWC Web Role - sRootPath = E:
This is because:
-
In Full IIS
configuration, the Web Role is running in WaIISHost.exe process however to Web
Site is running in w3wp.exe.
-
In HWC web role,
both the role and web site is running in WaWebHost.exe process.
-
With Full IIS the
web site process is not only a different appdomain but a different process
launched by a different service.
-
Because of it the
situation becomes complex to pass the role environment variables to web site.
-
You can write code
to pass this data via the registry or file system.
-
You can read service
configuration settings using the RoleEnvironment.GetConfigurationSettings.
Comments
Anonymous
May 26, 2011
Hi Avkash Thanks for this post. RoleEnvironment.GetConfigurationSettings() is an unknown method - what version of the sdk is this?Anonymous
June 21, 2011
It’s been a great pleasure to thank you for this informative article. I will always recommend your article and refer to my friend too for the same.Anonymous
September 03, 2014
When I am using a WebRole deployed to Azure, I can use RoleEnvironment in my RoleEntryPoint as well as my website (running in the cloud service in a w3wp). However if I add another Site this site cannot access RoleEnvironment. Why is it that one website can, but another cannot? This is with SDK 2.4 stackoverflow.com/.../cannot-access-roleenviroment-when-running-multiple-sites-inside-cloud-service