tags:

views:

32

answers:

2

Hi Cannot understand why this works in a web (changing to WebConfigManager) but not in a winapp.When I go a look at the config file is still not encrypted!!Am I missing something? Can You help?

 EncryptionUtility.ProtectSection("connectionStrings", "DataProtectionConfigurationProvider");

public class EncryptionUtility
 {
  public static void ProtectSection(string sectionName,string provider)
  {
   var config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);

   var section = config.GetSection(sectionName);

   if (section == null || section.SectionInformation.IsProtected) return;
   section.SectionInformation.ProtectSection(provider);
   config.Save();
  }

  public  static void UnProtectSection(string sectionName)
  {
   var config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);

   var section = config.GetSection(sectionName);

   if (section == null || !section.SectionInformation.IsProtected) return;
   section.SectionInformation.UnprotectSection();
   config.Save();
  }
 }

A: 

In winforms you have 3 config files: one in the project, on in the debug directory and one in release directory. Are you sure you trying to encrypt the right one?

Alex Reitbort
silly question how do I know which one I am encrypting?
jo
the one near executing exe, called <my_exe_name.exe.config>
Alex Reitbort
A: 

thanks I looked and it;s encrypted. Should set the config file in the app to never copy. Clarify one thing for me if you can. It modifies the app.config in the bin\debug or release but it never modifies the one in the project.Is this correct? how can you also make modify the one in the project? thanks a lot

jo