2
我有myapp.somenamespace.exe.config
文件带有connectionStrings节,我需要加密。还有一些我想要的完整的其他配置设置。所以我写了这个小工具,它会做到这一点:修改配置节将该节保存到不同的配置文件
class Program
{
static void Main(string[] args)
{
EncryptSection("myapp.somenamespace.exe.config", "connectionStrings");
}
static void EncryptSection(string fileName, string sectionName)
{
var config = ConfigurationManager.OpenExeConfiguration(fileName);
var section = config.GetSection(sectionName);
if (section.SectionInformation.IsProtected) return;
secction.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
config.Save();
}
}
会发生什么,它创建了一个名为myapp.somenamespace.exe.config.config
一个新的配置文件 - 添加重复.config
扩展,仅包含加密部分。它不是修改原始配置文件。
任何想法为什么这样一个奇怪的行为,我怎么能解决这个问题?
太好了,非常感谢! – Andrey 2013-04-11 14:48:38
@Andrey,我很高兴我可以帮助! – 2013-04-11 14:49:03