When an Azure worker role starts up, I need to update one of the value in it's app.config with a dynamic value.
I tried:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["sampleName"].Value = "sampleValue";
config.Save(ConfigurationSaveMode.Minimal);
ConfigurationManager.RefreshSection("appSettings");
But it throws UnauthorizedException during start up. Is there any recommended way of doing it?
If that code is in your OnStart method, then it is too late to update the app.config since the process is already running. You need to do this from a startup task. There is an example using Powershell at http://blogs.msdn.com/b/cie/archive/2013/11/14/enable-server-gc-mode-for-your-worker-role.aspx.