Moving to Azure some changes to the old way of using web.config must be done. Connection strings and applications settings that used to be in the web.config, might have to move to the cloud as well.
A rule of thumb is that settings that change with each deployment could still be in the web.config. But settings that remains constants, but are different in staging and production must be in the ConfigurationSettings in ServiceConfiguration.cscfg.
ServiceDefinition.csdef:
<ConfigurationSettings>
<Setting name="MyConnectionString" />
</ConfigurationSettings>
ServiceConfiguration.cscfg:
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
<Setting name="MyConnectionString" value="server=tcp:XXX.database.windows.net; database=YYY; user id=ZZZ@XXX; password=***" />
</ConfigurationSettings>
Inside your code you can access this setting like this:
var connectionString = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue("MyConnectionString");

No comments:
Post a Comment