using System.Web.Configuration;
using System.Configuration;
public Class Config
{
private void EncryptConfig( bool isEncrypt )
{
string path = "/webSite1";
System.Configuration.Configuration config =WebConfigurationManager.OpenWebConfiguration ( path );
ConfigurationSection section = config.GetSection( "connectionstrings" );
if( isEncrypt )
{
section.SectionInformation.ProtectSection( "DataProtectionConfigurationProvider" );
}
else
{
section.SectionInformation.UntProtectSection();
}
config.Save();
}
}
web.config 文件:
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings>
<add name="SimpleNorthwindsConnectionString1" connectionString="Data Source=deskzilla;Initial Catalog=SimpleNorthwinds;Persist Security Info=True;User ID=scott;Password=pw1337"
providerName="System.Data.SqlClient" />
<add name="TasksConnectionString1" connectionString="Data Source=JAMES-DONG;Initial Catalog=Tasks;User ID=sa;Pooling=False"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
</system.web>
</configuration>