【发布时间】:2011-12-12 03:10:14
【问题描述】:
我在 web.config 中的连接字符串的加密功能存在问题。
加密工作完美!但是一旦启用加密,我就会丢失我的会话变量内容(会话变量上的空异常)。
当我在 web.config 中停用我的连接字符串的加密时,一切恢复正常。
这是我的连接字符串加密代码:
#region Constructeur
static QueryManager()
{
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
ConnectionStringsSection section = config.GetSection("connectionStrings") as
ConnectionStringsSection;
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
config.Save(ConfigurationSaveMode.Minimal);
}
if ((myConnectionString =
ConfigurationManager.ConnectionStrings["DBConnect"].ConnectionString) == null)
{
throw new ConfigurationErrorsException("Database server not configured");
}
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
config.Save(ConfigurationSaveMode.Minimal);
}
#endregion
感谢您的帮助!
【问题讨论】: