我有一个应用程序,它对配置文件中的一个部分进行加密。第一次尝试从配置文件中读取加密部分时,会收到错误消息:“未识别属性'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文件立即更新,但出于某种原因,我需要重新启动应用程序才能使用加密部分。