/// /// 加密指定區塊 /// private void EncryptWebConfigByDPAPI() { Configuration configuration = null; ConfigurationSection connectionSection = null; //打開Req... ...
/// <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(); } }