ConfigurationManager and web.config and ASP.NET refresh curiosity

G

Guest

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
 
B

Brock Allen

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! :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top