Hi,
I am trying to encrypt the appSettings and connectionStrings section in App.config file of the console application. For some reason section.SectionInformation.IsProtected is always returning true.
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();
}
}
Not sure why it is always returning true.