您的位置:首页 > 其它

(对Web.config文件加密)encrypting sensitive information stored in the web.config file

2007-04-22 13:46 453 查看
为了系统安全,需要对数据库的连接字符串进行加密:

1.引入Configuration名称空间 :


using System.Web.Configuration;

2.加密代码如下:


protected void EncryptConfig(bool bEncrypt)




...{


string path = "/SMTWeb";


Configuration config = WebConfigurationManager.OpenWebConfiguration(path);


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


if (bEncrypt)




...{


appSettings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");


}


else




...{


appSettings.SectionInformation.UnprotectSection();


}


config.Save();


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐