2008-09-03 126 views
2

我遇到了以前遇到的问题;找不到我如何解决它的参考。App.config连接字符串保护错误

这是问题。我们加密在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 
+2

如果您使用的是Vista或更高版本,请确保您以管理员身份运行。 – 2010-09-22 12:48:13

回答

1

我在自己的原始答案中找到了一个更优雅的解决方案。我发现,如果我只登录为日谁orignally安装该应用程序EUSER并引起了配置文件的ConnectionStrings进行加密,并去到.NET Framework目录中commadn提示和运行

aspnet_regiis -pa "NetFrameworkConfigurationKey" "{domain}\{user}" 

它给其他用户访问RSA加密密钥容器的权限,然后它适用于其他用户。

只是想在这里补充它,因为我认为我已经在博客中对我们的开发博客这个问题,但在这里找到,所以在情况下,我需要看看它再次就在这里。在这个主题中也会添加到我们开发者博客的链接。

+0

这也有助于从ASP .NET应用程序中获取该错误。 aspnet_Regiis -pa“NetFrameworkConfigurationKey ASPNET 谢谢 – Jay 2009-07-08 14:52:43

0

听起来像一个权限问题。有问题的(新)用户对app.config文件有写入权限?以前的用户是否可以掩盖此问题的本地管理员或超级用户?

+0

我们使用clickonce install安装了新用户的应用程序。这两个用户都在PC上的管理员组中。从我在网上发现的情况来看,它似乎是默认的RSA密钥是特定于计算机的事实,当不同的用户使用它来保护他们的app.config版本时,它会导致错误。我想我需要使用一些用户特定的密钥来保护,现在只需要知道如何。 :) 感谢回复! Mike – MikeScott8 2008-09-03 17:58:37

1

所以我确实得到它的工作。

  1. 去除老用户的笔记本电脑占
  2. 复位app.config中有部分没有从所有用户机键
  3. 跑的应用程序保护
  4. 删除密钥文件,并允许它保护部分

但所有这一切都让它为这个用户工作。

现在我需要知道我必须做的改变代码,以保护部分,因此在PC上多个用户可以使用该应用程序。我来这里的虚拟PC(在明天到下周三休假到WDW后)!

任何建议,以帮助指引我在正确的方向,因为我不是很有经验的这种RSA加密类型的东西。

1

http://blogs.msdn.com/mosharaf/archive/2005/11/17/protectedConfiguration.aspx#1657603

复制和粘贴:d

周一,2007年2月12日上午12:15由耐擦洗

回复:使用加密的配置文件保护配置

这里我所做的所有步骤的列表,以加密我的PC上的两个部分,然后将其部署到WebServer。也许它会帮助别人...:

  1. 创建计算机级别的RSA密钥容器

    aspnet_regiis -pc "DataProtectionConfigurationProviderKeys" -exp 
    
  2. 前connectionStrings节这web.config中加入:

    <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 />!重要与encripting播放/ decripting多次

  3. 检查在Web.config文件的顶部有这种时候。如果缺少添加:

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> 
    
  4. 保存并在VS密切Web.Config文件(!非常重要)

  5. 在命令提示符(本地PC)窗口去:

    C:\ WINNT \ Microsoft.NET \框架\ V2.0.50727

  6. 加密:(注意更改物理性路径的应用程序,或使用-app选项给应用程序的名称虚拟目录!因为我在PC上使用了VS,所以我最好选择下面的选项。的路径是路径Web.config文件)

    ASPNET_REGIIS -pef “的ConnectionStrings” “C:\布拉\布拉\布拉” -prov “DataProtectionConfigurationProvider”

    ASPNET_REGIIS -pef “的System.Web /成员” “C:\布拉\布拉\布拉” -prov “DataProtectionConfigurationProvider”

  7. 解密(如果只需要!)(!如果只需要)

    aspnet_regiis -pdf "connectionStrings" "c:\Bla\Bla\Bla" 
    
    aspnet_regiis -pdf "system.web/membership" "c:\Bla\Bla\Bla" 
    
  8. Delete键集装箱

    aspnet_regiis -pz "DataProtectionConfigurationProviderKeys" 
    
  9. 保存上述关键XML文件中以便将其从本地PC导出到Web服务器(UAT或生产)

    aspnet_regiis -px "DataProtectionConfigurationProviderKeys" \temp\mykeyfile.xml -pri 
    
  10. 导入密钥容器WebServer的服务器上:

    aspnet_regiis -pi "DataProtectionConfigurationProviderKeys" \temp\mykeyfile.xml 
    
  11. 授予访问键在Web服务器上

    aspnet_regiis -pa "DataProtectionConfigurationProviderKeys" "DOMAIN\User" 
    

    请参阅IIS中的ASP。(仅在必要!)

    Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name 
    
  12. 删除授权访问Web服务器上的关键

    aspnet_regiis -pr "DataProtectionConfigurationProviderKeys" "Domain\User" 
    
  13. 复制并粘贴到web服务器加密的Web.config文件:NET用户或使用。