0

i want to give the values of username,password and APIKey in web.config which are coming from database.means whatever the admin set username,password,APIkey that has to be set in web.config. how can i change this.Any idea.

thank you.

1 Answers1

0
 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();
   }
}

But it will restart your application domain every time you update the web.config file, so, updating the web.config frequently is not advisable.

Pls refer : Editing Web.config programatically

Community
  • 1
  • 1
Thurein
  • 6,645
  • 5
  • 22
  • 23