保存配置文件时出错 [英] Error in saving config file

查看:182
本文介绍了保存配置文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!



我正在尝试将MappedExe配置文件保存在用户的AppData目录中。

当我尝试保存加密时出现问题connectionString。



这是异常的消息:

Hello!

I am trying to save MappedExe configuration file within user's AppData directory.
Problem occurs when I try to save encrypted connectionString.

This is the exception's message :

"System.Configuration.ConfigurationErrorsException: An error occured executing section handler for connectionStrings.-->System.Configuration.ConfigurationErrorsException: Failed to encrypt the section 'connectionStrings' using provider 'RsaProtectedConfigurationProvider'. Error message from provider: Object already exists.





它只发生在域内的普通用户,我没有管理员,高级用户,工作组等问题。



这是负责保存配置数据的代码的一部分:





It only occurs with common users within domain, I have no problems with admins, power users, work-groups etc.

This is part of code responsible for saving configuration data:

if (_configuration.ConnectionStrings.ConnectionStrings[Application.ProductName] == null)
{
    _configuration.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings(Application.ProductName, 
                                                                                        _connStringBuilder.ToString()));
}
else
{
    _configuration.ConnectionStrings.ConnectionStrings[Application.ProductName].ConnectionString = _connStringBuilder.ToString();
}
try
{
    if (!_configuration.ConnectionStrings.SectionInformation.IsProtected)
    {
        _configuration.ConnectionStrings.SectionInformation.ForceSave = true;
        _configuration.ConnectionStrings.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
    }

    _configuration.Save(ConfigurationSaveMode.Minimal);
}
catch (Exception ex)
{
#if DEBUG
    MessageBox.Show(ex.ToString() + "\n" + ex.StackTrace);
#else
    throw;
#endif
}







你能帮帮我吗?



P.S.这是一个ClickOnce解决方案。




Can you help me?

P.S. This is a ClickOnce solution.

推荐答案

实际加密基于RSA密钥或DPAPI,这意味着密钥存储在本地计算机中。解密只能在加密app配置的机器上完成(除非你导出RSA密钥并将其导入另一台机器)。
The actual encryption is either based on an RSA key or DPAPI, which means the key is stored in the local machine. The decryption can only be done on the machine where the app config was encrypted (unless you export the RSA key and import it into another machine).


整个问题的根源是域用户的事实权利是受限制的这种保护(在windir内偷看),所以我不得不修补问题。

我已经制定了加密和解密的自定义方法,它工作正常。 br />


我对延迟回答道歉。
Source of entire problem is fact that domain user's rights are to restricted for this kind of protection ("peeking" inside windir), so I had to tinker around the problem.
I've made custom methods for encryption and decryption and it works fine.

My apologies for delayed answer.


你需要以管理员身份运行命令;)
You need to run command as administrator ;)


这篇关于保存配置文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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