我有一个应用程序,它有一些特定的设置,如erroremailid,maxcapcount等。我将这些值存储在appsetting块中。 任何人都可以告诉我在以下两个选项之间哪个更好(性能明智):1。在web.config中存储设置2.在普通xml文件中存储设置然后读取它们
一些指定性能差异的文章也会很好。
谢谢Ashwani
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 performance difference will also be good.
Thanks Ashwani
最满意答案
重点不在于性能,为什么你认为.NET框架在读取一个xml文件和另一个xml文件时会更快?
.NET的工作方式是从应用程序配置文件中检索某些设置(不仅仅是appSettings部分),该文件是ASP.NET的web.config和可执行应用程序的exefile.exe.config 。
在Windows窗体应用程序等可执行文件中,您也可以在运行时在配置文件中保存应用程序中的设置,但在ASP.NET中,即使API相同也可以调用save方法,web.config也不会更新,因为它是以readonly身份打开,因为每次更改IIS都会重新启动Web应用程序。
没有办法想象将一些其他自定义设置放在另一个单独的XML文件中会更慢或更快,与web.config的优势在于您可以随时编辑此类xml文件而无需重新启动Web应用程序会在您保存web.config中的更改时发生。
仍然。 .NET将从web.config获取appSettings,因此您只能在其他文件中放入其他类型的设置,然后您必须自己手动读取这些设置,不确定是否可以指示ConfigurationManager从其他文件读取。
web.config中还有许多其他部分由应用程序的其他部分使用,如果您将它们移动到某处,.NET将不会自动为您提供这些部分,例如默认的SMTP服务器。
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.
更多推荐
发布评论