I have below code running. Changing an appSetting in my webconfig. But I have to make a extra pageload to "make the magic".
1st. pageload. uses previous setting. second pageload. Okay.
I have it placed inside Page_PreInit
:
Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appSettings = (AppSettingsSection)configuration.GetSection("appSettings");
appSettings.Settings["FileManager"].Value = "newValue";
configuration.Save();
If you mean the codes that run after This code by "first page load" this is something normal.
Config file just lunches after a request (and before preInit).
i think the only solution is making that extra page load.