基于 Duplicate Connection String Error问题 我在添加连接字符串之前添加了一个 remove
标签。这解决了原始问题的问题。
但是,当我对 web.config 文件应用 RSA 加密(使用 aspnet_regiis)时,错误又回来了。
Parser Error Message: The entry 'theConnectionString' has already been added.
我认为,加密时,它不会调用“删除”语句。是这样吗?此问题有任何解决方法吗?
原始连接字符串
<connectionStrings>
<remove name="theConnectionString" />
<add name="theConnectionString" ... />
<connectionStrings>
加密配置
最佳答案
通过使用 Clear
而不是 Remove
作为连接字符串部分中的第一条语句,我可以解决问题。
注意:即使在我手动解密配置文件后,Clear
仍会保留。但加解密后Remove
不保留。 [感谢@Oded 发表评论来检查]
引用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.
关于asp.net - 加密的配置文件不应用 connectionStrings 中的 “remove” 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16547034/