Encryption Sections of Web.config in ASP.NET 2.0

You can easily encrypt sections of web.config in ASP.NET 2.0. In the code below I have encrypted the ConnectionStrings section of web.config. Also check out the complete article which also includes writing into configuration files dynamically and reading configuration settings.

 Configuration config = WebConfigurationManager
 .OpenWebConfiguration(Request.ApplicationPath);

ConfigurationSection configSection = config.GetSection("connectionStrings");

if (configSection.SectionInformation.IsProtected)

{

configSection.SectionInformation.UnprotectSection();

config.Save();

}

else

{

configSection.SectionInformation.ProtectSection

("DataProtectionConfigurationProvider");

config.Save();

}

powered by IMHO 1.3

Print | posted @ Monday, January 16, 2006 11:56 PM

Twitter