The below sample C# code shows how to change the key value of Appsettings in the web.config file dynamically.
web.config file settings:- <appSettings>
<add key = "Delay" value = "5" />
</appSettings>
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";
AppConfigSettings.Save();