0
votes

Working with a series of websites that programmatically sets some appSettings values per website by simply looping through user-specified values that are stored in a database.

foreach (DataRow dr in result.Tables[0].Rows) {
    ConfigurationManager.AppSettings.Set(dr["app_key_name"].ToString(), dr["app_key_value"].ToString());
}

This allows each site to use the same codebase, but have different variables defined and accessible.

The problem is that one (of many) sites seems to frequently lose the programmatically added appSettings. The few appSettings that are set within the Web.Config file remain, but the ones that were added programmatically seem to fail sometimes, or not reload when the site recycles.

Should these variables be check on Application_BeginRequest and re-added if they don't exist? Thoughts?

1

1 Answers

0
votes

Don't you need to invoke Save()?:

    config.Save(System.Configuration.ConfigurationSaveMode.Modified)