我遇到了以前遇到的问题;找不到我关于如何解决该问题的引用。
问题就在这里。我们使用以下代码对客户端应用程序的 app.config 中的连接字符串部分进行加密:
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
If config.ConnectionStrings.SectionInformation.IsProtected = False Then
config.ConnectionStrings.SectionInformation.ProtectSection(Nothing)
' We must save the changes to the configuration file.'
config.Save(ConfigurationSaveMode.Modified, True)
End If
问题是我们有一名销售人员休假。旧笔记本电脑将交给新销售人员,并在新用户登录下,当它尝试执行此操作时,我们会收到错误。错误是:
Unhandled Exception: System.Configuration.ConfigurationErrorsException:
An error occurred executing the configuration section handler for connectionStrings. ---> System.Configuration.ConfigurationErrorsException: Failed to encrypt the section 'connectionStrings' using provider 'RsaProtectedConfigurationProvider'.
Error message from the provider: Object already exists.
---> System.Security.Cryptography.CryptographicException: Object already exists
最佳答案
http://blogs.msdn.com/mosharaf/archive/2005/11/17/protectedConfiguration.aspx#1657603
复制并粘贴:D
2007 年 2 月 12 日星期一 12:15 由 Naica 发布
回复:使用 protected 配置加密配置文件
以下是我在 PC 上加密两个部分然后将其部署到 Web 服务器所执行的所有步骤的列表。也许它会对某人有所帮助...:
创建计算机级 RSA key 容器
aspnet_regiis -pc "DataProtectionConfigurationProviderKeys" -exp
将其添加到 web.config 中的 connectionStrings 部分之前:
<add name="DataProtectionConfigurationProvider" type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" keyContainerName="DataProtectionConfigurationProviderKeys" useMachineContainer="true" />
不要错过
<clear />
从上面!多次加密/解密时很重要检查是否将其置于 Web.Config 文件的顶部。如果缺少,请添加:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
在VS中保存并关闭Web.Config文件(非常重要!)
在命令提示符(我的本地电脑)窗口中转到:
C:\WINNT\Microsoft.NET\Framework\v2.0.50727
加密:(请注意更改应用程序的物理路径,或使用 -app 选项并为应用程序提供虚拟目录的名称!因为我在 PC 上使用 VS,所以我更喜欢以下选项。路径是Web.config 文件的路径)
aspnet_regiis -pef“connectionStrings”“c:\Bla\Bla\Bla”-prov“DataProtectionConfigurationProvider”
aspnet_regiis -pef“system.web/membership”“c:\Bla\Bla\Bla”-prov“DataProtectionConfigurationProvider”
解密(仅在需要时!):
aspnet_regiis -pdf "connectionStrings" "c:\Bla\Bla\Bla" aspnet_regiis -pdf "system.web/membership" "c:\Bla\Bla\Bla"
删除 key 容器(仅在需要时!)
aspnet_regiis -pz "DataProtectionConfigurationProviderKeys"
将上述 key 保存到 xml 文件,以便将其从本地 PC 导出到 Web 服务器(UAT 或 Production)
aspnet_regiis -px "DataProtectionConfigurationProviderKeys" \temp\mykeyfile.xml -pri
在 WebServer 服务器上导入 key 容器:
aspnet_regiis -pi "DataProtectionConfigurationProviderKeys" \temp\mykeyfile.xml
授予对网络服务器上 key 的访问权限
aspnet_regiis -pa "DataProtectionConfigurationProviderKeys" "DOMAIN\User"
在 IIS 中查看 ASP.NET 用户或使用:
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name
删除授予对网络服务器上 key 的访问权限(仅在需要时!)
aspnet_regiis -pr "DataProtectionConfigurationProviderKeys" "Domain\User"
将加密的 Web.config 文件复制并粘贴到 WebServer。
关于vb.net - App.config 连接字符串保护错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42115/