.net加密web.config文件
/// <summary> /// 加密指定区块 /// </summary> private void EncryptWebConfigByDPAPI() { Configuration configuration = null; ConfigurationSection connectionSection = null; //打开Request所在路径网站的Web.config文件 configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); //取得Web.config中connectionStrings设置区块 connectionSection = configuration.GetSection("connectionStrings"); //未加密时 if (!connectionSection.SectionInformation.IsProtected) { connectionSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); configuration.Save(); } } /// <summary> /// 解密指定区块 /// </summary> private void EncryptWebConfig() { Configuration configuration = null; ConfigurationSection connectionSection = null; //打开Request所在路径网站的Web.config文件 configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); //取得Web.config中connectionStrings设置区块 connectionSection = configuration.GetSection("connectionStrings"); if (connectionSection != null && connectionSection.SectionInformation.IsProtected) { connectionSection.SectionInformation.UnprotectSection(); configuration.Save(); } }
相关推荐
逍遥友 2020-11-20
hellowordmonkey 2020-11-02
gloria0 2020-10-26
zyshappy 2020-08-16
pythonwangjunji 2020-08-16
Equation 2020-08-09
iamjiyu 2020-07-21
winxcoder 2020-07-18
lepton 2020-07-04
zzdadexiaoha 2020-06-28
ajuan 2020-06-25
tosim 2020-06-24
wghou 2020-06-21
yudiewenyuan 2020-06-21
JessePinkmen 2020-06-14
heimu 2020-06-12
limx 2020-06-11
zghover 2020-06-11