Configuration config = WebConfigurationManager.OpenWebConfiguration("/"); ConfigurationSection appSettings = config.GetSection("appSettings"); if (appSettings.SectionInformation.IsProtected) { appSettings.SectionInformation.UnprotectSection(); } else { appSettings.SectionInformation.ProtectSection( "DataProtectionConfigurationProvider"); } config.Save();