App.config - 加密部分错误:

Joe*_*Joe 5 .net c# xml configuration

我有一个应用程序加密配置文件中的一个部分.在我第一次尝试从配置文件中读取加密部分时,我收到一条错误消息:"无法识别的属性'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");
Run Code Online (Sandbox Code Playgroud)

这只发生在我第一次尝试读取加密部分时.我注意到.config文件在第一次保存后立即更新,但出于某种原因我需要重新启动应用程序才能使用加密部分.

Joe*_*Joe 1

供您参考,问题是尝试加密配置部分的进程没有管理员权限。我将此过程添加到管理员组并解决了它。