【发布时间】:2026-01-24 09:40:01
【问题描述】:
我的 app.web.config 有自定义配置部分 NameValueSectionHandler,但 aspnet_regiis 找不到它。
我需要将我的 WPF 应用程序部署到多台机器上,并对其 app.config 进行加密。我已经尝试了许多使用 aspnet_regiis 的演练,但没有任何效果。我试过了:
- 将 app.config 重命名为 app.web.config
- 创建公钥容器
aspnet_regiis -pc LiteContainer -exp - 我一直在加密自定义配置部分
aspnet_regiis -pef connectionSettings D:\Tes -prov LiteProvider
错误是
“未找到配置部分'connectionSettings'”。
失败!
但我可以通过代码成功地读取/写入该部分的数据。
应用程序/Web.config
<configuration>
<configSections>
<section name="connectionSettings" type="System.Configuration.NameValueSectionHandler"/>
<sectionGroup name="userSettings" .... </sectionGroup>
</configSections>
<connectionSettings>
<server>192.168.1.xxx</server>
<database>myDb</database>
<uid>root</uid>
<pwd>123</pwd>
</connectionSettings>
<configProtectedData>
<providers>
<add name="LiteProvider"
keyContainerName="LiteContainer"
useMachineContainer="true"
description="Uses RsaCryptoServiceProvider to encrypt and decrypt"
type="System.Configuration.RsaProtectedConfigurationProvider/>
</providers>
</configProtectedData>
</configuration>
我之前没有看到任何演练加密NameValueSectionHandler,很多人使用过applicationSettings 或connectionStrings。我在这里错过了什么?
【问题讨论】:
-
等等,你为什么在 WPF 的 app.config 上使用 aspnet_regiis?好的,我没有意识到你可以做到这一点,你是否遵循这些确切的步骤? social.msdn.microsoft.com/Forums/windows/en-US/…
-
因为许多人说这是可能的,暂时将其重命名为
web.config并稍后重命名为.config是可以的。另外 aspnet_regiis 仅适用于web.config -
我已经尝试了这些步骤
-
D:\Tes 是包含您的 web.config 的文件夹吗?
-
是的,它位于
D:\Tes
标签: c# .net wpf encryption config