1.为了使相关配置文件更加安全,有时需要对其进行加密操作,下面是一组对appSections加密的操作
Configuration config = WebConfigurationManager.OpenWebConfigruation("/");
ConfiguratoinSection appSec = config.GetSection("connectionStrings");
if(appSec.SectionInformation.IsProtected)
{
appSec.SectionInformation.UnprotectSection();
}
else
{
appSec.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}
config.save();
操作完成后;可在web.config文件中观察connectionStrings变化