I' trying to update key value from code behind and it seemed like web.config updated but value didn't saved.
appSetting there is nothing special:
<appSettings>
<add key="Default" value="1.11"/>
<add key="Company" value="1.078"/>
<add key="Customer" value="1.1"/>
</appSettings>
Here is the code that must update appSettings key value:
Protected Sub btnSaveDefault_Click(sender As Object, e As System.EventArgs) Handles btnSaveDefault.Click
Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("/")
config.AppSettings.Settings.Item("Default").Value = tbDefault.Text
config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")
End Sub
hope this help ...
System.Configuration.Configuration objConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
objConfig.AppSettings.Settings["DEFAULT_PASSWORD"].Value = password;
objConfig.Save();
follow this link .. Getting error while changing Appsettings value in Web config from code behind
Well. I found solution myself. The problem was in the other piece of code.
So each time on Page Load code giving me old value and If Page.IsPostBack fixed this issue.
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
tbCompany.Text = Convert.ToSingle(ConfigurationManager.AppSettings("Company"))
tbDefault.Text = Convert.ToSingle(ConfigurationManager.AppSettings("Default"))
tbUser.Text = Convert.ToSingle(ConfigurationManager.AppSettings("Customer"))
End If
End Sub