我用RSAProtectedConfigurationProvider加密配置文件里的连接字符串后,在本机正常运行,但一把web.config文件上传到网站虚拟主机里 就提示"……打不开 RSA 密钥容器……" 查了资料知道这种情况是加解密不在同一台电脑上造成的。。大虾们,如何解决????先谢了
解决方案 »
- 遍历DataList控件后如何给他绑定数据库呢?
- 求一个正则表达式
- VS2005 数据无法写入数据库
- 纯CS文件,如何调用一个url而不用新打开页面
- static变量可以做窗体间参数传递吗?新手求助,谢谢
- WndProc中WM_LBUTTONDOWN的问题。
- vs2010中.cs打不开是什么原因
- FileSystemWatcher unable to watch network drive as a windows service
- 系统允许几天就会出现这样的问题,“未将对象引用设置到对象的实例。”
- 俺找到的一个很不错的.net技术论坛!~~~~~~~~~~~~
- C#访问远程数据库问题
- 依据公式计算任一因子
使用“DataProtectionConfigurationProvider”形式加密,创建test.aspx文件,代码如下:
需要添加引用
using System.Web.Configuration;
using System.IO;//加密
protected void Button1_Click(object sender, EventArgs e)
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.GetSection("connectionStrings");
if (section != null && !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
config.Save();
} }
//解密
protected void Button2_Click(object sender, EventArgs e)
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.GetSection("connectionStrings"); if (section != null && section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
config.Save();
}
}
总结:此方法很方便,并且很简单,但安全性没有密钥加密高。方法二
使用“RSAProtectedConfigurationProvider”形式来加密
test.aspx程序文件基本如上,
把section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
改成section.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider");
但这个时候你访问网站的时候很有可能会出现说明: 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。
分析器错误信息: 未能使用提供程序“RsaProtectedConfigurationProvider”进行解密。提供程序返回错误信息为: 打不开 RSA 密钥容器。这样的错误,解决方法是:
进dos运行:aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT AUTHORITY\NETWORK SERVICE"
如果运行出错,需要把目录 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 放入环境变量path中。
此时就可以成功访问网站了。
同样可以通过命令行来实现“RSAProtectedConfigurationProvider”加密