国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#加密app.config中連接字符串的方法

2020-01-24 01:36:45
字體:
供稿:網(wǎng)友

本文實(shí)例講述了C#加密app.config中連接字符串的方法。分享給大家供大家參考。具體如下:

連接字符串中包含數(shù)據(jù)庫的訪問信息,帳號(hào)和密碼,因此一般不以明文顯示,本代碼用來加密連接字符串。

public static class EncryptConnection{  public static void EncryptConnectionString(bool encrypt)  {   Configuration configFile = null;   try   {    // Open the configuration file and retrieve the connectionStrings section.    configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);    ConnectionStringsSection configSection = configFile.GetSection("connectionStrings") as ConnectionStringsSection;    if ((!(configSection.ElementInformation.IsLocked)) && (!(configSection.SectionInformation.IsLocked)))    {     if (encrypt && !configSection.SectionInformation.IsProtected)     //encrypt is false to unencrypt     {      configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");     }     if (!encrypt && configSection.SectionInformation.IsProtected)     //encrypt is true so encrypt     {      configSection.SectionInformation.UnprotectSection();     }     //re-save the configuration file section     configSection.SectionInformation.ForceSave = true;     // Save the current configuration.     configFile.Save();    }       }   catch (System.Exception ex)   {    throw (ex);   }   finally   {   }  }}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 怀远县| 揭阳市| 宜阳县| 登封市| 武夷山市| 县级市| 长武县| 东至县| 晋宁县| 平原县| 喀什市| 佛教| 广灵县| 栖霞市| 安溪县| 烟台市| 林甸县| 靖宇县| 张家口市| 陈巴尔虎旗| 冕宁县| 新郑市| 麦盖提县| 毕节市| 尤溪县| 康乐县| 花莲市| 漳浦县| 浑源县| 长乐市| 石首市| 鹿泉市| 连江县| 江陵县| 当阳市| 南昌市| 南京市| 晋中市| 贵州省| 满洲里市| 阿图什市|