gpt4 book ai didi

asp.net - ConfigurationManager.AppSettings 缓存

转载 作者:行者123 更新时间:2023-12-02 08:50:14 25 4
gpt4 key购买 nike

我们知道 IIS 会缓存 ConfigurationManager.AppSettings,因此它只会读取磁盘一次,直到 web.config 更改为止。这样做是为了性能目的。

某人在:

http://forums.asp.net/p/1080926/1598469.aspx#1598469

指出 .NET Framework 不会对 app.config 执行相同的操作,但它会针对每个请求从磁盘读取。但我发现很难相信,因为它会更慢。请告诉我他错了,否则我将不得不修复我编写的每个控制台/Windows 窗体/Windows 服务。

更新我很遗憾我误解了人们在上面链接的论坛中所说的话。

最佳答案

快速测试似乎表明这些设置仅在应用程序启动时加载。

//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();

您会看到所有输出保持不变。

关于asp.net - ConfigurationManager.AppSettings 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/389361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com