Saturday, March 24, 2012

web.config settings - are they read on every page request?

I have a question regarding the way settings in the web.config file are accessed.

Lets take, for exampe, a custom entry in the<appSettings> secton

<

appSettings>
<addkey="MyKeyName"value="MyValue"/>
</appSettings>

When I access this key programmatically --[ConfigurationManager.AppSettings["MyKeyName"].ToString(); ] -- is the web.config file being physically read every time I access any one key from it? or Are the settings of the web.config file loaded into memory and therefore I'm accessing the settings without creating extra Disk I/O?

Thanks in advance for your help.

Regards,

Jose Lopez

First of all, if you are using ASP.NET 2.0, you should now be using WebConfigurationManager class instead.

How many appSettings you have?? 1000? or more? I don't believe this should be a source of worry to you!

Regards


I don't know the answer, but here's a great way to find out for yourself.

Read the value, manually change it in your web.config, and read the value again.


Haidar,

Yes, I am using ASP.NET 2.0. I will look as the WebConfigurationManager class as you suggest.

By you mentioning 1000 appSettings or more, does that confirm my assumption? i.e. That the web.config file is "physically read (disk I/O)" every time I access a key value? So, the entries in the web.config file are NOT loaded into memory, is this right?

Would you please confirm if you have the answer?

Thanks.


I believe it does make the physicall read every time you access a key value. I believe so, because after you change a value in your web.config file you do not need to recompile your application or do any sort of fumbling with IIS.

Lav


Michael,

Thanks for your suggestion. If I change the value I will immediately see the change but any time you chahge the web.config settings the changes are immediate. My question is more along the way these settings are loaded, whether by reading the file (disk I/O) or memory resident.

Regards


Read through article at following link. you will get ur answer.

"At run time ASP.NET uses these web.config configuration files to hierarchically compute a unique collection of settings for each incoming URL target request (these settings are calculated only once and then cached across subsequent requests; ASP.NET automatically watches for file changes and will invalidate the cache if any of the configuration files change). "

http://dotnetjunkies.com/quickstart/aspplus/doc/configformat.aspx

Thanks


The values for the Web.config are stored into cache/memory when the application starts hence why the app restarts when any changes are made to the web.config. Note that this only applies to the Web.config, any other .config files you may use are accessed from the disk by default.


Lav,

Thank you. Exactly what I was looking for.

Thanks to all who replied to this post and helped me find the answer.

Best regards!

0 comments:

Post a Comment