【发布时间】:2009-10-20 11:22:42
【问题描述】:
我需要从后面的代码中加密 web.config 中的连接字符串和一些 appsettings 键值。
请帮忙。
【问题讨论】:
标签: c# .net asp.net web-config
我需要从后面的代码中加密 web.config 中的连接字符串和一些 appsettings 键值。
请帮忙。
【问题讨论】:
标签: c# .net asp.net web-config
【讨论】:
试试这个
private void ProtectSection(string sectionName,
string provider)
{
Configuration config =
WebConfigurationManager.
OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section =
config.GetSection(sectionName);
if (section != null &&
!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(provider);
config.Save();
}
}
【讨论】: