Changing the Web.config file key value at runtime using C#.

Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 571
The below sample C# code shows how to change the key value of Appsettings in the web.config file dynamically.
web.config file settings:-
<add key = "Delay" value = "5" />

We have to import System.Web.Configuration and System.Configuration Namespaces.
using System.Web.Configuration;
using System.Configuration;

Configuration AppConfigSettings = WebConfigurationManager.OpenWebConfiguration("~");
AppConfigSettings.AppSettings.Settings["Delay"].Value = "20";

Comments or Responses

Login to post response