App.config 连接字符串保护错误 [英] App.config connection string Protection error

查看:30
本文介绍了App.config 连接字符串保护错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以前遇到的问题;找不到关于如何解决它的参考.

I am running into an issue I had before; can't find my reference on how to solve it.

问题来了.我们使用以下代码为我们的客户端应用程序加密 app.config 中的连接字符串部分:

Here is the issue. We encrypt the connection strings section in the app.config for our client application using code below:

        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

问题是我们有一名销售人员请假.旧笔记本电脑将要交给新的销售人员,并在新用户的登录下进行,当它尝试执行此操作时,我们会收到错误消息.错误是:

The issue is we had a salesperson leave. The old laptop is going to a new salesperson and under the new user's login, when it tries to to do this we get an error. The error is:

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

推荐答案

我找到了一个更优雅的解决方案,在我对自己的原始答案中.我发现如果我只是以最初安装应用程序的用户身份登录并导致配置文件连接字符串被加密并在命令提示符下转到 .net 框架目录并运行

I found a more elegant solution that in my original answer to myself. I found if I just logged in as th euser who orignally installed the application and caused the config file connectionstrings to be encrypted and go to the .net framework directory in a commadn prompt and run

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

它授予其他用户访问 RSA 加密密钥容器的权限,然后它对其他用户有效.

it gave the other user permission to access the RSA encryption key container and it then works for the other user(s).

只是想在这里添加它,因为我以为我已经在我们的开发博客上写了这个问题,但在这里找到了它,所以如果我需要再次查找它会在这里.还将在此线程中添加指向我们的开发博客点的链接.

Just wanted to add it here as I thought I had blogged this issue on our dev blog but found it here, so in case I need to look it up again it will be here. Will add link to our dev blog point at this thread as well.

这篇关于App.config 连接字符串保护错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆