Change Daynamic Web.config File

Add Reference

  1. using System.Configuration;  
  2. using System.Web.Configuration;  
Out Put Data Web.config File
  1. <appSettings>  
  2.     <add key="TEST" value="123" />-----------------------------------------Change Value  
  3.     <add key="webpages:Version" value="2.0.0.0" />  
  4.     <add key="webpages:Enabled" value="false" />  
  5.     <add key="PreserveLoginUrl" value="true" />  
  6.     <add key="ClientValidationEnabled" value="true" />  
  7.     <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings>  
C# Code
  1. public JsonResult WebConfigChange()  
  2. {  
  3.     var configuration = WebConfigurationManager.OpenWebConfiguration("~"); //Get All Data Web.config File  
  4.     var Section = (AppSettingsSection) configuration.GetSection("appSettings"); // Get <appSetting>  
  5.     Section.Settings["TEST"].Value = "123"//Value Replace  
  6.     configuration.Save(); //Replace Web.config File  
  7.     return Json(new  
  8.     {  
  9.         Data = "Success"  
  10.     }, JsonRequestBehavior.AllowGet);  
  11. }