简体   繁体   English

启动Azure工作角色上的app.config更新

[英]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.

相关问题 如何在不重新发布Azure Worker Role Service的情况下更新我的app.config文件 - How can I update my app.config file without republishing Azure Worker Role Service 带有额外DLL和app.Config的AZURE Worker Role Deploy - AZURE Worker Role Deploy with extra DLL's and app.Config 组合的Azure Web角色和辅助角色项目在部署时未看到app.config - Combined Azure web role and worker role project not seeing app.config when deployed 有没有办法使用Slow Cheetah转换Azure Worker角色中的app.config? - Is there a way to use Slow Cheetah to transform app.config in Azure Worker Role? 适用于Azure中多个辅助角色的App.config转换 - App.config transformations for multiple worker roles in Azure 针对辅助角色配置的WaIISHost.exe.config与app.config - WaIISHost.exe.config vs. app.config for worker role config 对于Azure Worker角色,cscfg文件和App.config文件如何相互关联? - How do cscfg files and App.config files relate to one another for Azure Worker Roles? Web角色中的app.config未复制到Azure SDK 1.8和Visual Studio 2010中 - app.config in Web Role not copied in Azure SDK 1.8 and Visual Studio 2010 Azure Worker角色还是Web应用程序? - Azure Worker Role or Web App? Azure辅助角色配置文件转换 - Azure Worker Role Config File Transformations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM