ASP.NET web.config appsettings持久性

时间:2022-03-19 03:25:08

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?

我正在检查从配置文件中检索appsettings值的方法。之前我将值存储在全局ConfigurationManager类中的静态变量中,以避免对web.config文件进行多次不必要的磁盘读取。看来这是不必要的,因为WebConfigurationManager类已经这样做了。确实如此吗?如果我连续10次发出以下命令,它实际访问web.config文件的次数是多少?

myConfigValue = WebConfigurationManager.AppSettings["MyConfigValue"];

myConfigValue = WebConfigurationManager.AppSettings [“MyConfigValue”];

2 个解决方案

#1


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.

它必须每次都对你的“MyConfigValue”字符串进行查找,所以如果你可以把它放在你只需要做一次这个部分的地方,那么可能还有一些改进空间。

Either way, it's a micro-optimization.

无论哪种方式,它都是微观优化。

#2


none. the web.config file is read once, on application start...

没有。在应用程序启动时,web.config文件被读取一次...

http://www.google.com/search?hl=en&q=web.config+changes+require+iis+restart&btnG=Google+Search&aq=f&oq=&aqi=

#1


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.

它必须每次都对你的“MyConfigValue”字符串进行查找,所以如果你可以把它放在你只需要做一次这个部分的地方,那么可能还有一些改进空间。

Either way, it's a micro-optimization.

无论哪种方式,它都是微观优化。

#2


none. the web.config file is read once, on application start...

没有。在应用程序启动时,web.config文件被读取一次...

http://www.google.com/search?hl=en&q=web.config+changes+require+iis+restart&btnG=Google+Search&aq=f&oq=&aqi=