Mike Cole
Mike Cole

Reputation: 14713

ASP.NET web.config appsettings persistence

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"];

Upvotes: 2

Views: 955

Answers (2)

Tim Hoolihan
Tim Hoolihan

Reputation: 12396

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=

Upvotes: 3

Joel Coehoorn
Joel Coehoorn

Reputation: 415735

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.

Upvotes: 3

Related Questions