简体   繁体   中英

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:

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

Is there a way to fix this?

Jonny S is right. 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. You can use roleenvironmentchanging event to manage how a role instance responds to a configuration change.

For more info on roleenvironmentchanging event check http://msdn.microsoft.com/en-us/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:

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

You can change the values in the ServiceConfiguration through the Management Portal once deployed.

If you RDP into the web role you should be able to add permissions to the web.config file for the logged in user. You can then modify the web.config. As @Adil mentions this will cause the AppDomain to recycle so should only really be done as a last resort.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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