asp.net - 加密的配置文件不应用 connectionStrings 中的 “remove” 标记

标签 asp.net

基于 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>

加密配置

enter image description here

最佳答案

通过使用 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/

相关文章:

asp.net - 为什么 FindControl 在中继器的页脚中找不到该按钮?

asp.net - 错误是运行所选代码生成器时出错 :invalid pointer(Exception from HRESULT:0x80004003(E_POINTER))

asp.net - css3 - 自定义下拉列表

html - 从特定网页 Div 中获取图像标签

c# - 如何使用 VS2013 MVC5 模板显示自定义配置文件信息?

c# - 如何从 1 个特定页面的布局中删除 HTML 元素?

asp.net - Css 验证在 asp 网络中不起作用

c# - LINQ "queries"是否被编译成实际的 SQL 存储过程?

c# - 获取角色内的所有用户。 ASP.NET 标识

html - css不申请asp.net超链接