我有一个加密的<connectionString>
部分,我试图将其保存在.config文件中。当我的程序在调试或发布模式下运行时,我可以打开MyApp.vshost.exe.config
并查看加密部分。退出我的应用程序并再次打开它后,<connectionString>
部分丢失了
我的应用程序需要管理权限,如果它有任何区别。
它运行在.NET 4.5.1上。 C#中的答案很受欢迎。
Dim builder As SqlClient.SqlConnectionStringBuilder =
New SqlClient.SqlConnectionStringBuilder(conneStr.ToString)
Dim config As System.Configuration.Configuration =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim section As ConnectionStringsSection =
DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection)
Dim connSettings As ConnectionStringSettings =
New ConnectionStringSettings("mySqlConnection",
builder.ConnectionString,
builder.ConnectionString)
section.ConnectionStrings.Add(connSettings)
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
section.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Full)
ConfigurationManager.RefreshSection("connectionStrings")