【发布时间】:2011-10-22 02:05:29
【问题描述】:
我在应用程序的开头运行以下方法,传入位于 applicationSettings 下的部分:
public static void EncryptConfigSection(string sectionKey)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection(sectionKey);
if (section != null)
{
if (!section.SectionInformation.IsProtected)
{
if (!section.ElementInformation.IsLocked)
{
section.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection(sectionKey);
}
}
}
}
这是 app.config 中的部分示例:
<applicationSettings>
<Example.Properties.Settings>
<setting name="Key" serializeAs="String">
<value>Value</value>
</setting>
</Example.Properties.Settings>
</applicationSettings>
当我尝试访问该部分的任何设置时,我收到以下错误:
无法识别的属性“configProtectionProvider”
这是一个桌面应用程序,需要在启动时加密一些设置,然后在退出时解密。
有人有解决这个问题的办法吗?
【问题讨论】: