App.Config Encrypt section, not saving
-
Hi, I'm having difficulty getting a section of an app.config file to show as encrypted. I run the code and get no errors, but the section does not encrypt. Any help would be appreciated, I've tried other implementations from other posts here with same results: using System; using System.Windows.Forms; using System.Configuration; namespace AppConfigRedux { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnUnprotect_Click(object sender, EventArgs e) { UnProtectSection("connectionStrings"); } private void btnProtect_Click(object sender, EventArgs e) { ProtectSection("connectionStrings", "DataProtectionConfigurationProvider"); } private void ProtectSection(string sectionName, string provider) { Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath); ConfigurationSection section = config.GetSection(sectionName); if (section != null && !section.SectionInformation.IsProtected) { section.SectionInformation.ProtectSection(provider); config.Save(); } } private void UnProtectSection(string sectionName) { Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath); ConfigurationSection section = config.GetSection(sectionName); if (section != null && section.SectionInformation.IsProtected) { section.SectionInformation.UnprotectSection(); config.Save(); } } } }