C# 在asp.net C中加密连接字符串时出现奇怪的错误#
我想在发送源代码以供查看时对连接字符串进行加密。因此,我在C# 在asp.net C中加密连接字符串时出现奇怪的错误#,c#,asp.net,encryption,web-config,C#,Asp.net,Encryption,Web Config,我想在发送源代码以供查看时对连接字符串进行加密。因此,我在Global.asax文件中执行类似的操作 void Application_Start(object sender, EventArgs e) { // Code that runs on application startup EncryptConnString(); } public static void EncryptConnString() { Configuration config = S
Global.asax
文件中执行类似的操作
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
EncryptConnString();
}
public static void EncryptConnString()
{
Configuration config = System.Web.Configuration
.WebConfigurationManager
.OpenWebConfiguration("~");
ConfigurationSection section = config.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
config.Save();
}
}
但是在这一行config.Save()代码>我得到一些奇怪的错误,如下所示
System.Configuration.dll中出现“System.Configuration.ConfigurationErrorsException”类型的异常,但未在用户代码中处理
其他信息:执行ConnectionString的配置节处理程序时出错
我找不到它的原因,因为它是标准代码加密它。请说明可能的原因我相信您没有正确设置连接字符串的加密。请考虑这个答案-> @ Aristos:什么样的设置?我在前面的答案上添加了一个链接,有详细信息…@Aristos:现在我知道了,但是在哪里添加这个部分,它将授予我访问该类的权限aspnet\u regiis-pa“NetFrameworkConfigurationKey”“{domain}\{user}”
??