加密的配置文件不适用于connectionStrings中的“删除"标签 [英] Encrypted config file does not apply “remove” tag in connectionStrings

查看:49
本文介绍了加密的配置文件不适用于connectionStrings中的“删除"标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于

machine.config文件还包含一个connectionStrings部分,其中包含Visual Studio使用的连接字符串.从Windows应用程序中的app.config文件中按提供者名称检索连接字符串时,将首先加载machine.config中的连接字符串,然后再加载app.config中的条目.在connectionStrings元素从内存中的数据结构中删除所有继承的引用后立即添加 clear ,以便仅考虑在本地app.config文件中定义的连接字符串.

Based on Duplicate Connection String Error question I have added a remove tag before adding connectionstring. That resolved the problem for the original question.

But, when I applied RSA encryption for the web.config file (using aspnet_regiis) the error came back.

Parser Error Message: The entry 'theConnectionString' has already been added.

I think, when encrypted, it is not calling the ‘remove’ statement. Is it so? Any workaround for this issue?

Original Connectionstring

<connectionStrings>
 <remove name="theConnectionString" />
 <add name="theConnectionString" ... />
<connectionStrings>

Encrypted Config

解决方案

By using Clear instead of Remove as the first statement in the connectionstrings section, I could resolve the problem.

Note: Clear is retained even after I manually decrypted the config file. But Remove is not retained after encryption-decryption. [Thanks to @Oded for giving a comment to check this]

Refer Connection Strings and Configuration Files

The machine.config file also contains a connectionStrings section, which contains connection strings used by Visual Studio. When retrieving connection strings by provider name from the app.config file in a Windows application, the connection strings in machine.config get loaded first, and then the entries from app.config. Adding clear immediately after the connectionStrings element removes all inherited references from the data structure in memory, so that only the connection strings defined in the local app.config file are considered.

这篇关于加密的配置文件不适用于connectionStrings中的“删除"标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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