You can easily change any AppSettings value in web.config during runtime from your C# code by using WebConfigurationManager.
Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appSettings = (AppSettingsSection)configuration.GetSection("appSettings");
if (appSettings != null)
{
appSettings.Settings["SetupRan"].Value = "true";
configuration.Save();
}
This will set SatupRan to true in web.config
<appSettings>
<add key="SetupRan" value="true"/>
</appSettings>
WebConfigurationManager Provides access to Web application’s configuration files and the GetSection methods can be used to get any section in web.config.
Posted
21 Nov 2009 6:22 AM
by
Gal Ratner