web.config in asp.net
i want to give the values of username,password and APIKey i开发者_C百科n 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.
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
精彩评论