Changing value on appSettings webconfig. Only works on second pageload

203 views Asked by At

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();
1

There are 1 answers

2
aliCna On

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.