简体   繁体   English

在运行时更改云服务web.config

[英]Changing cloud service web.config at runtime

I'm trying to change the web.config of a deployed cloud service (WCF in this case) on Windows Azure, and when I try to change the appSettings in the web.config at runtime, I'm getting permission denied error: 我正在尝试在Windows Azure上更改已部署的云服务(在本例中为WCF)的web.config,当我尝试在运行时更改web.config中的appSettings时,出现权限被拒绝错误:

Access to the path 'E:\sitesroot\0\web.config' is denied.

Is there a way to fix this? 有没有办法解决这个问题?

Jonny S is right. 乔尼S是正确的。 You should store settings you want to change at runtime in the role configuration. 您应该将要在运行时更改的设置存储在角色配置中。 The web.config changes will be lost if Azure moves your VM and in a multi-instance scenario your instances will be out of sync. 如果Azure移动您的VM,则web.config更改将丢失,并且在多实例方案中,您的实例将不同步。 You can use roleenvironmentchanging event to manage how a role instance responds to a configuration change. 您可以使用roleenvironmentchanging事件来管理角色实例如何响应配置更改。

For more info on roleenvironmentchanging event check http://msdn.microsoft.com/en-us/library/windowsazure/gg432963.aspx 有关roleenvironmentchanging事件的更多信息,请访问http://msdn.microsoft.com/zh-cn/library/windowsazure/gg432963.aspx

You should store any settings you need to change at runtime in the ServiceConfiguration (cscfg) of your Role and then use the following in your code to retrieve the setting: 您应该将在运行时需要更改的所有设置存储在Role的ServiceConfiguration(cscfg)中,然后在代码中使用以下内容来检索该设置:

string setting = RoleEnvironment.GetConfigurationSettingValue("myConfigSetting");

You can change the values in the ServiceConfiguration through the Management Portal once deployed. 部署后,您可以通过管理门户更改ServiceConfiguration中的值。

If you RDP into the web role you should be able to add permissions to the web.config file for the logged in user. 如果您将RDP设置为Web角色,则应该能够为登录用户的web.config文件添加权限。 You can then modify the web.config. 然后,您可以修改web.config。 As @Adil mentions this will cause the AppDomain to recycle so should only really be done as a last resort. 正如@Adil提到的那样,这将导致AppDomain回收,因此仅应在万不得已的情况下进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM