tags:

views:

308

answers:

2

I'm reviewing my method for retrieving appsettings values from my config files. Before I would store the value in a static variable in a global ConfigurationManager class to avoid multiple unnecessary disk reads to the web.config file. It appears that was unnecessary as the WebConfigurationManager class already does this. Is this indeed the case? If I issue the following command 10 times in a row, how many times would it actually access the web.config file?

myConfigValue = WebConfigurationManager.AppSettings["MyConfigValue"];

+3  A: 

It would only go to disk one time, and even then it probably already did it at the first request for any page in the app.

It will have to do a lookup on your "MyConfigValue" string each time, so there might be some room for improvement if you can put this somewhere that you only need to do that part once.

Either way, it's a micro-optimization.

Joel Coehoorn
Thank you for confirming. If I modify the web.config file while the application is running, will .NET re-read the value from web.config?
Mike C.
Thanks for the additional info. I think I'll quit sweating the small stuff.
Mike C.
+3  A: 

none. the web.config file is read once, on application start...

http://www.google.com/search?hl=en&q=web.config+changes+require+iis+restart&btnG=Google+Search&aq=f&oq=&aqi=

Tim Hoolihan