A quick reminder:
After Windows Azure SDK 1.3, we now use full IIS instead HWC (Hosted Web Core). Using IIS we can have several WebSites per WebRole, so now the internal architecture and processes are different, this is why we have to change the we we use the API regarding Windows Azure configuration settings.
Basically, in case you’re using ASP.NET, we need to add the following code to our Global.asax
Global.asax in ASP.NET
protected void Application_Start()
{
//(CDLTLL) Configuration for Windows Azure settings
CloudStorageAccount.SetConfigurationSettingPublisher(
(configName, configSettingPublisher) =>
{
var connectionString =
RoleEnvironment.GetConfigurationSettingValue(configName);
configSettingPublisher(connectionString);
}
);
}
Here is an interesting post regarding how to solve this issue, for detailed information:
Then, if you want to get a connection string (like ADO.NET or EF connString) from WA-Conf-Settings or from a regular Web.config, depending on what environment you are running your app, you can check if you are running on Windows Azure using ‘RoleEnvironment.IsAvailable’, so doing the following can be very useful:
CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
{
string connectionString;
if (RoleEnvironment.IsAvailable)
{
connectionString = RoleEnvironment.GetConfigurationSettingValue(configName);
}
else
{
connectionString = ConfigurationManager.AppSettings[configName];
}
configSetter(connectionString);
});
0 comments