Saturday, 3 October 2015

Decrypt web config file - asp.net

Leave a Comment
This is example how to decrypt web config file in asp.net. You can refer to this post on how to encrypt web config file.

The example will decrypt web config file for 3 section which is ConnectionString, AppSetting, and system.web/authentication .

Front End aspx code

  <br />  
   This is button to decrypt web config.<br />  
   <asp:Button ID="Button2" runat="server" Text="Decrypt Web Config" OnClick="Button2_Click" />  


Code behind

  private static string[] sectionName = { "connectionStrings", "appSettings", "system.web/authentication" };  
     public static string[] SectionName  
     {  
       get  
       {  
         return sectionName;  
       }  
       set  
       {  
         sectionName = value;  
       }  
     }  
     protected void Button2_Click(object sender, EventArgs e)  
     {  
       //decrypt  
       UnProtectSection();  
     }  
     /// <summary>  
     /// Decrypted web config file for certain section  
     /// </summary>  
     /// <param name="sectionName"></param>  
     private void UnProtectSection()  
     {  
       foreach (string a in SectionName)  
       {  
         Configuration config =  
           WebConfigurationManager.  
             OpenWebConfiguration("~/");  
         ConfigurationSection section =  
              config.GetSection(a);  
         if (section != null &&  
            section.SectionInformation.IsProtected)  
         {  
           section.SectionInformation.UnprotectSection();  
           config.Save();  
         }  
       }  
     }  

Output







By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.