c# Protecting a connectionstring in a configuration file

  1. private void DataProtectionAPI()   
  2. {   
  3.     try   
  4.     {   
  5.         System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(   
  6.         System.Reflection.Assembly.GetExecutingAssembly().Location);   
  7.   
  8.         ConnectionStringsSection section =   
  9.         config.GetSection("connectionStrings"as ConnectionStringsSection;   
  10.   
  11.         if (!section.SectionInformation.IsProtected)   
  12.         {   
  13.             section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");   
  14.             config.Save();   
  15.         }   
  16.   
  17.     }   
  18.     catch   
  19.     {   
  20.     }   
  21. }  

No comments:

Post a Comment