Posts Changing appSettings value in web.config
Post
Cancel

Changing appSettings value in web.config

Following is the simple code to change the value of the appSettings key,

private void UpdateConfig(string strKey, string strValue)
{
Configuration objConfig = WebConfigurationManager.OpenWebConfiguration(”~”); 
AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection(”appSettings”);
if (objAppsettings != null)
{
objAppsettings.Settings[strKey].Value = strValue; 
objConfig.Save();
}
}
This post is licensed under CC BY 4.0 by the author.