ConfigurationManager.AppSettings缓存 [英] ConfigurationManager.AppSettings Caching
问题描述
我们知道,IIS缓存ConfigurationManager.AppSettings,所以它读取磁盘只有一次,直到web.config中被改变。这样做是为了提高性能的目的做了。
We know that IIS caches ConfigurationManager.AppSettings so it reads the disk only once until the web.config is changed. This is done for performance purposes.
在有人
<一个href=\"http://forums.asp.net/p/1080926/1598469.aspx#1598469\">http://forums.asp.net/p/1080926/1598469.aspx#1598469
表示,.NET Framework并不是对的app.config做相同,但它从磁盘为每一个请求读取。但我觉得很难相信,因为这将是慢。请告诉我,他是错的,不然我就必须解决每个控制台/ Windows窗体/ Windows服务我写的。
stated that .NET Framework doesn't do the same for app.config, but it reads from the disk for every request. But I find it hard to believe, 'cause it would be slower. Please tell me that he is wrong or I'll have to fix every Console/Windows Forms/Windows Services I wrote.
更新我很遗憾,我misinter preTED什么人在上面的链接的论坛上说。
Update I regret that I misinterpreted what people said in the linked forum above.
推荐答案
一个快速测试,似乎表明,这些设置只装载在应用程序启动。
A quick test seems to show that these settings are only loaded at application startup.
//edit the config file now.
Console.ReadLine();
Console.WriteLine(ConfigurationManager.AppSettings["ApplicationName"].ToString());
Console.WriteLine("Press enter to redisplay");
//edit the config file again now.
Console.ReadLine();
Console.WriteLine(ConfigurationManager.AppSettings["ApplicationName"].ToString());
Console.ReadLine();
您会看到所有的输出保持不变。
You'll see that all outputs remain the same.
这篇关于ConfigurationManager.AppSettings缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!