开发者

Difference between web.config and normal xml file for storing application settings

开发者 https://www.devze.com 2023-04-06 21:52 出处:网络
I have an application which have some specific settings like erroremailid, maxcapcount etc. I am storing these values in appsetting block. Can anybody tell me which will be better (performance wise)

I have an application which have some specific settings like erroremailid, maxcapcount etc. I am storing these values in appsetting block. Can anybody tell me which will be better (performance wise) between following two options: 1. Storing settings in web.config 2. Storing settings in normal xml file and then reading them

Some articles specifying the pe开发者_Python百科rformance difference will also be good.

Thanks Ashwani


The point is not about performances, why do you think the .NET framework would be any faster in reading one xml file vs another one?

The way .NET works is that certain settings (not only the appSettings section) are retrieved from the application configuration file which is web.config for ASP.NET and exefile.exe.config for executable applications.

in executables like windows forms applications you can also save settings from the app at runtime in the config file but in ASP.NET even if the APIs being the same will let you call the save method, the web.config will not be updated as it's opened as readonly because every time it is changed IIS restarts the web application.

there is no way to imagine that putting some other custom settings in another separated XML file would be any slower or any faster, the advantage vs the web.config would be that you can edit such xml file anytime without the web app to restart as it would happen anytime you save changes in web.config.

still. .NET will get the appSettings from web.config so you can put in another file only other kind of settings and then you have to read those settings yourself by hand, not sure if you can instruct the ConfigurationManager to read from another file.

There are many other sections inside the web.config that are taken by other parts of the application and if you would move them somewhere .NET would not automatically take those for you, for example the default SMTP Server.


you have several classes already at your disposal that allow you to read settings from your web.config. if you choose to use your own xml file you will have to write the code to read the values yourself (not that it is particularly difficult, though)

performance wise, the web.config values are read once and strored in memory (again, you could do this yourself if you implement your own class to read settings from your xml) therefore it's fast.

the other difference is that asp.net detects changes to the web.config file automatically and loads them again when this happens. so potentially you can point your app, for example, to a different database at runtime w/o recycling the application. and the application will pick up the changes immediately w/o you recycling the app manually.


webconfig for settings that are not going to change (Can use built in methods to make them update on the fly though).

If you have a lot of settings that are being changed, then storing as a seperate XML would be a better solution, since you can update them on the fly.

EDIT:

After finding some new information it is possible to use webconfig settings on the fly as well using built in methods. (See Icarus's answer)

0

精彩评论

暂无评论...
验证码 换一张
取 消