ConfigurationManager and web.config and ASP.NET refresh curiosity

Discussion in 'ASP .Net' started by =?Utf-8?B?SmF5IEhpbHlhcmQ=?=, Apr 5, 2005.

  1. Hi all,

    I was playing with the new ConfigurationManager class in the Feb CTP drop of
    VS 2005 and I noticed that if you make changes to the configuration inside of
    an ASP.NET page, those changes are immediately written to the web.config when
    you say Configuration.Save() but if I then try to access them, they do not
    appear to refresh within the request.

    Not completely unexpected I suppose but I was wondering if anyone knew if
    this is the way this is supposed to work or if the current request should
    have picked up the changes?

    Basically I added a new sqlCacheDependency using the configuration classes
    and then called the constructor of SqlCacheDependency with the corresponding
    information and it threw an exception because it couldn't find the setting I
    just wrote out to the web.config. I got around it by doing a
    response.redirect back to the page again and then executing the constructor
    which worked but if the changes won't take until a new page loads then I'd
    just like to know that is the case.

    Thanks in advance for any help on this.

    Jay
    =?Utf-8?B?SmF5IEhpbHlhcmQ=?=, Apr 5, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?SmF5IEhpbHlhcmQ=?=

    Brock Allen Guest

    > I was playing with the new ConfigurationManager class in the Feb CTP
    > drop of VS 2005 and I noticed that if you make changes to the
    > configuration inside of an ASP.NET page, those changes are immediately
    > written to the web.config when you say Configuration.Save() but if I
    > then try to access them, they do not appear to refresh within the
    > request.


    The reason is that the request is executing inside of an AppDomain that has
    cached the settings of the config file prior to the modification. You request
    makes changes which invalidates the cached config data. Upon the next request
    ASP.NET will launch a new AppDomain to load the new settings. So changes
    made won't be visible until the next request into the application.

    > Not completely unexpected I suppose but I was wondering if anyone knew
    > if this is the way this is supposed to work or if the current request
    > should have picked up the changes?


    So, from above, no this is not to be expected. If your request were to see
    the changes immediaetly it would require creating the AppDomain and somehow
    passing the current request (mid-stream) over to the new AppDomain that has
    loaded the new settings. In short, it doesn't do this, so you won't see the
    changed settings.

    > Basically I added a new sqlCacheDependency using the configuration
    > classes and then called the constructor of SqlCacheDependency with the
    > corresponding information and it threw an exception because it
    > couldn't find the setting I just wrote out to the web.config. I got
    > around it by doing a response.redirect back to the page again and then
    > executing the constructor which worked but if the changes won't take
    > until a new page loads then I'd just like to know that is the case.


    Voila! :)

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen
    Brock Allen, Apr 5, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    1
    Views:
    676
    Christopher Reed
    Jan 11, 2006
  2. Ben Fidge
    Replies:
    1
    Views:
    2,303
    Teemu Keiski
    Feb 11, 2006
  3. SR
    Replies:
    1
    Views:
    847
  4. CSharpner
    Replies:
    0
    Views:
    1,001
    CSharpner
    Apr 9, 2007
  5. Michel Racicot

    Custom Control and ConfigurationManager

    Michel Racicot, Oct 22, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    322
    Gregory A. Beamer
    Oct 23, 2009
Loading...

Share This Page