【发布时间】:2010-10-14 21:40:09
【问题描述】:
我有一个加密配置文件中的部分的应用程序。在我第一次尝试从配置文件中读取加密部分时,我收到一条错误消息:“无法识别的属性 'configProtectionProvider'。请注意,属性名称区分大小写。”
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Get the section in the file.
ConfigurationSection section = config.GetSection("EncryptedSection");
if (section != null)
{
// Protect the section.
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
section.SectionInformation.ForceSave = true;
// Save the change.
config.Save(ConfigurationSaveMode.Modified);
}
ConfigurationManager.RefreshSection("EncryptedSection");
Properties.Settings.Default.Reset();
//This is the part where I read the encrypted section:
ConfigurationManager.RefreshSection("EncryptedSection");
System.Collections.IDictionary HSMMasterKeyConfig = (System.Collections.IDictionary)System.Configuration.ConfigurationManager.GetSection("EncryptedSection");
这只发生在我第一次尝试阅读加密部分时。我注意到 .config 文件在第一次保存后立即更新,但由于某种原因,我需要重新启动应用程序才能使用加密部分。
【问题讨论】:
-
哼,在运行时修改配置文件不是典型的用法。您或许应该在 Microsoft Connect 上报告问题。
标签: c# .net xml configuration