Code to Encrypt Connection String in Web.Config File
using System.Configuration;
using System.Web.Configuration;
using System.Web.Security;
public void EncryptConnectionString()
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
config.Save();
}
}
public void DecryptConnectionString()
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.GetSection("connectionStrings");
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
config.Save();
}
This entry was posted
on Wednesday, April 07, 2010
and is filed under
Asp.net
.
You can leave a response
and follow any responses to this entry through the
Subscribe to:
Post Comments (Atom)
.