2014-04-01 76 views
6

我用我的aspx加載中的代碼加密web.config中的連接字符串。解密web.config中的connectionString?

protected void Page_Load(object sender, EventArgs e) 
{ 
    Configuration config =  WebConfigurationManager.OpenWebConfiguration("~"); 

    ConnectionStringsSection connSection = (ConnectionStringsSection)config.GetSection("connectionStrings"); 

    connSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); 

    config.Save(); 
} 

我是c#的新手,現在我需要的是解密。任何想法如何?

我只能使用下面的代碼解密一行。

protected void Page_Load(object sender, EventArgs e) 
{ 
    Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); 

    ConnectionStringsSection connSection = (ConnectionStringsSection)config.GetSection("connectionStrings"); 

    //connSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); 
    connSection.SectionInformation.UnprotectSection(); 

    config.Save(); 
} 

謝謝。

+3

這是否幫助? http://msdn.microsoft.com/en-us/library/dtkwfdky(v=vs.100).aspx –

+0

謝謝!!它幫助我! – user3357141

回答

1

我發現這裏怎麼辦呢https://msdn.microsoft.com/en-us/library/dtkwfdky(v=vs.100).aspx

我可以僅通過改變下面的代碼的一行解密:

protected void Page_Load(object sender, EventArgs e) 
{ 
    Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); 

    ConnectionStringsSection connSection = (ConnectionStringsSection)config.GetSection("connectionStrings"); 
    //connSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); 
    connSection.SectionInformation.UnprotectSection(); 

    config.Save(); 
} 
相關問題