繁体   English   中英

使用aspnet_regiis加密应用程序或Web.config-找不到“ xyz”部分

[英]Encrypt App or Web.config using aspnet_regiis - Section 'xyz' not found

我的app.web.config具有自定义配置部分NameValueSectionHandler ,但是aspnet_regiis找不到它。

我需要将我的WPF应用程序部署到加密了app.config的多台计算机上。 我已经尝试过使用aspnet_regiis进行许多演练,但是没有任何效果。 我试过了:

  1. 将app.config重命名为app.web.config
  2. 创建公共密钥容器aspnet_regiis -pc LiteContainer -exp
  3. 我被困在加密自定义配置部分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进行加密,许多使用过的applicationSettingsconnectionStrings 我在这里想念什么?

在此处输入图片说明

我认为您的命令是错误的,即使文件夹D:\\ Tes包含您的web.config:

aspnet_regiis -pef connectionSettings D:\\Tes -prov LiteProvider

您输入的是connectionSettings而不是connectionStrings

%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pef "connectionStrings" <full path to directory containing web.config file>

语法不是aspnet_regiis -pef [节名] [web.config路径]吗? 该部分的名称是connectionSettings而不是connectionStrings


这是在PC上尝试时的结果。

  1. 将具有AppSettings( 或ConnectionStrings )部分的App.Config复制到C:\\ Temp,并将其重命名为Web.config。

  2. 运行此命令:%windir%\\ Microsoft.NET \\ Framework \\ v2.0.50727 \\ aspnet_regiis -pef“ appSettings” c:\\ Temp

在此处输入图片说明

运行aspnet_regiis命令后,将对appSettings进行加密:

在此处输入图片说明

  1. 将C:\\ Temp \\ Web.Config重命名为App.Config

您的XML格式不符合预期,例如:

<server>192.168.1.xxx</server>
  <database>myDb</database>
  <uid>root</uid>

使用标准的appSettings或connectionStrings格式:

<appSettings>
    <add key="server" value="192.168.1.xxx"/>
    <add key="database" value="myDb"/>
    <add key="uid" value="root"/>
    <add key="pwd" value="123"/>
</appSettings>

参考: https : //social.msdn.microsoft.com/Forums/windows/zh-CN/3b5a1d1f-aa57-40d8-8607-fee0b2a8a6db/protect-appconfig-file-or-encrypt? forum =winforms

https://docs.microsoft.com/en-us/dotnet/api/system.configuration.configurationmanager.appsettings?view=netframework-4.7.2

https://docs.microsoft.com/en-us/dotnet/api/system.configuration.configurationmanager.connectionstrings?view=netframework-4.7.2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM