1

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();
Pierre-Luc Pineault
  • 8,993
  • 6
  • 40
  • 55
user2761009
  • 85
  • 2
  • 16

1 Answers1

0

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.

aliCna
  • 45
  • 6
  • Thanks for replying. This sounds like a ninja trick... Can you tell me how to do that programmatically – user2761009 Dec 28 '13 at 13:07
  • you can use Response.Redirect("Page url.aspx?back=currentpageurl") and set it to come back with a request param like "currentpage.aspx?isback=1" and check for that in the page_preInt to run the code you want after it – aliCna Dec 29 '13 at 09:02