[英]Update app.config on Azure worker role start up
When an Azure worker role starts up, I need to update one of the value in it's app.config with a dynamic value. 当Azure辅助角色启动时,我需要使用动态值更新其app.config中的值之一。
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. 但是在启动过程中会引发UnauthorizedException。 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. 如果该代码在您的OnStart方法中,则更新app.config为时已晚,因为该进程已经在运行。 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 .
在http://blogs.msdn.com/b/cie/archive/2013/11/14/enable-server-gc-mode-for-your-worker-role.aspx中有一个使用Powershell的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.