Posts

Showing posts from September, 2013

Encrypting/Decrypting web.config sections in ASP.Net

using System.Configuration; using System.Web.Configuration; public partial class _Default : System.Web.UI. Page { protected void Encripting_Click( object sender, EventArgs e) { EncriptSection( "appSettings" , "DataProtectionConfigurationProvider" ); } protected void Decripting_Click( object sender, EventArgs e) { DecriptSection( "appSettings" ); } // section name may be connectionStrings, appSettings private void EncriptSection( string sectionName, string provider) { Configuration config = WebConfigurationManager .OpenWebConfiguration(Request.ApplicationPath); ConfigurationSection section =config.GetSection(sectionName); if (section != null && !section.SectionInformation.IsProtected) { section.SectionInformation.ProtectSection(provider); config.Save(); ...