I use my web.config file to store quite a few settings formy website. Some of these values get used very often. Is there a major performancehit if I access this file a lot? Is it slow accessing the web.config file?
No, there is not. In fact, it does not even access that file -- it is all loaded up into memory when the application starts up.
hi testvoid,
Once u access the config file, place the values in cache which will reduce the effort.
Tulasi
One more quetsion on this matter.
Where does these values get stored in memory? Is it stored as Session or Application variables?
Becuase if it is stored as Session variables performance will surelysuffer when many users visit the site. Because a set for each user mustthen be stored. Correct me if I am wrong.
OK just to be clear on this.
There is no point to load values that are in the web.config file intoSession or Application variables when the application or session startsbecause these values are loaded in any case?
They are not stored in an application or server variable. It does however appear on the same level as an application variable (in terms that all users share the same cached versions).
Hi testvoid,
to be clear, there are many reasons for not to store those settings in web.config.
One important thing to consider is that web.config is cached with a dependency on that file. This means that if the file gets modified, the cache for web.config is cleared and reloaded again with the new data.
I would recommend you storing your settings in an xml file, besides,
modifing web.config leads to Application restart, so for each change you make to your setting your web app will restart (and run all your initiallizations process).
After this, if your setting are at application level, you can place them as Application variables.
Be sure to lock (keyword) the Application object before doing any changes, to avoid multithreading errors.
Al last, check Microsoft's Enterprise Library Blocks, (especially Configuration Application Block) for easily storing and retrieving settings in files.
Thanks for the answers.
If what master4eva says is true (which I believe it is) I can't really see theuse of the application variable. The values in my web.config file will almostnever change and if the values stored in the web.config file has basically thesame functionality as an external settings file. Except you don't have to loadthese values yourself into Application variable.
Why would people actually use Application when using web.config is so convenient?
Cache is also one feature in ASP.NET making Application pretty much legacy stuff (to have compatibility with classic ASP).
0 comments:
Post a Comment