Encrypt+Config+Section  
Author Message
Thu Thu





PostPosted: .NET Base Class Library, Encrypt+Config+Section Top

static void Main()

{

//other code

// Protect the Connection Strings

ProtectConfiguration();

Application.Run(new MainForm());

}

static void ProtectConfiguration()

{

// TODO: Protect the Connection Strings

string provider = "RsaProtectedConfigurationProvider";

Configuration config = null;

config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

ConfigurationSection section = config.ConnectionStrings;

if ((section.SectionInformation.IsProtected == false) &&

(section.ElementInformation.IsLocked == false))

{

// Protect (encrypt) the "connectionStrings" section.

section.SectionInformation.ProtectSection(provider);

// Save the encrypted section.

section.SectionInformation.ForceSave = true;

config.Save(ConfigurationSaveMode.Full);

}

}

After I successfully run this window application, the app.config connection string section was not encrypted.

How would I do that works




.NET Development7  
 
 
Nathan Anderson - MSFT





PostPosted: .NET Base Class Library, Encrypt+Config+Section Top

Moving to Base Class Library forum.

Thanks.


 
 
Mark Benningfield





PostPosted: .NET Base Class Library, Encrypt+Config+Section Top

Hello All.

Thu Thu:

The app.config file is not the file that this code targets. Build your project as a Release version, which will produce the yourappname.exe.config file, which is the file that this code targets. Run the Release version of the app outside the VSHost de****, and your code will work.

HTH.