加密的 app.config 文件的性能问题

发布于 2024-11-08 00:39:52 字数 401 浏览 0 评论 0原文

我正在开发一个应用程序,出于多种原因,我们决定对 app.config 文件进行加密。我们使用 SectionInformation.ProtectSectionRsaProtectedConfigurationProvider 来加密所有部分。这部分工作正常,应用程序能够读取加密信息。我对这种方法的问题是关于性能的。我在对我们的应用程序进行负载测试时遇到了一个问题,其中使用加密配置在负载下比使用未加密配置几乎慢 2 倍。那么,当我的应用程序启动时,配置是否未加密并缓存在内存中?或者它实际上每次都会进入磁盘吗?我已经做了很多搜索,但还没有找到这里到底发生了什么的明确答案。感谢您的帮助!

我想补充一点,该应用程序大量使用 connectionString 属性来访问数据库。

i am working on an application where we have decided for a number of reasons that the app.config file should be encrypted. We are using SectionInformation.ProtectSection with the RsaProtectedConfigurationProvider to encrypt all of the sections. This part works fine and the application is able to read the encrypted information. My question with this approach is about performance. I have run into an issue load testing our application where using the encrpyted config is almost 2x slower under load than with an unencrypted config. So when my application starts up does the config get unencrypted and cached in memory or not? Or does it actually go to disk everytime? I have done alot of searching and have not found a difinitive answer to what exactly is going on here. Thanks for your help!

I'd like to add that this application uses the connectionString property a great deal to access the DB.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

身边 2024-11-15 00:39:52

我做了一个快速测试,看起来它已加载到内存中。下面是我运行的代码。在第一个 WriteLine() 之后,我打开配置,手动更改它,并保存配置文件。第二个 WriteLine() 打印出旧值而不是新值,因此我得出的结论是,它在读取一次后不会重新打开文件。

static void Main(string[] args)
{
    Console.WriteLine(ConfigurationManager.AppSettings("TestSettings"));
    Console.ReadLine();
    //Before hitting return I changed the value of TestSettings manually
    Console.WriteLine(ConfigurationManager.AppSettings("TestSettings"));
    Console.ReadLine();
}

I did a quick test and it looks like it's loaded into memory. Below is the code I ran. After the first WriteLine() I opened the config, manually changed it, and saved the config file. The second WriteLine() printed out the old value and not the new one,so I would conclude that it doesn't open the file back up after it reads it once.

static void Main(string[] args)
{
    Console.WriteLine(ConfigurationManager.AppSettings("TestSettings"));
    Console.ReadLine();
    //Before hitting return I changed the value of TestSettings manually
    Console.WriteLine(ConfigurationManager.AppSettings("TestSettings"));
    Console.ReadLine();
}
向地狱狂奔 2024-11-15 00:39:52

好吧,我找到了我自己问题的答案。事实证明,加密配置对性能的影响与我们解决方案框架代码中的错误有关。基本上,我们尝试实现的代码中留下了一些代码,每次我们访问连接字符串或任何应用程序设置时都会从磁盘打开配置:

var config = ConfigurationManager.OpenMappedExeConfiguration()

我将此代码更改为仅使用 ConfigurationManager.AppSettings[]< /code> 现在一切都运行良好。所以我发现,ConfigurationManager 在您第一次访问属性时从磁盘读取,并且仅在第一次时解密文件。之后,它只是从内存中解密的部分读取值。

Okay, i found the answer to my own question. As it turned out the performance hit i was taking with the encrypted config was related to a bug in our solution's framework code. Basically, there was left over code from something we were attemting to implement which was opening the config from disk everytime we went to access the connection string or any app setting:

var config = ConfigurationManager.OpenMappedExeConfiguration()

I changed this code to just use ConfigurationManager.AppSettings[] and everything is working great now. So what I found out was that ConfigurationManager reads from disk the first time you access a property and also decrypts the file that first time only. After that it's just reading the values from the decrypted sections in memory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文