6
我試圖加密控制檯應用程序的App.config文件中的appSettings
和connectionStrings
部分。由於某種原因,section.SectionInformation.IsProtected
總是返回true。保護App.config文件中的部分控制檯應用程序
static void Main(string[] args)
{
EncryptSection("connectionStrings", "DataProtectionConfigurationProvider");
}
private static void EncryptSection(string sectionName, string providerName)
{
string assemblyPath = Assembly.GetExecutingAssembly().Location;
Configuration config = ConfigurationManager.OpenExeConfiguration(assemblyPath);
ConfigurationSection section = config.GetSection(sectionName);
if (section != null && !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(providerName);
config.Save();
}
}
不知道爲什麼它總是返回true。