【问题标题】:How to encrypt .config file Asp.net如何加密 .config 文件 Asp.net
【发布时间】:2015-01-21 02:15:02
【问题描述】:

我想加密 common.config,而不是 Web.config 文件。 Common.config 与 web.config 位于不同的位置。 web.config 文件连接到 common.config。

web.config:

<appSettings file="C:\Users\ja\Documents\common.config">
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

common.config:

<appSettings>
    <add key="myKey" value="This is the Value"/>
</appSettings>`

这适用于 web.config 文件:

aspnet_regiis.exe -pef appSettings c:\Users\ja\Desktop\test\webapp\webapp -prov "RsaRpotectedConfigurationProvider"

但是当我尝试加密 common.config 文件时:

aspnet_regiis.exe -pef appSettings c:\Users\ja\Document\ -prov "RsaRpotectedConfigurationProvider"

我得到这个错误:

The configuration for physical path 'c:\Users\ja\Document\' cannot be opened

【问题讨论】:

    标签: asp.net web-config


    【解决方案1】:

    我找到了解决此问题的方法。希望对您有所帮助。

    1. 暂时将您的 common.config 重命名为 web.config。

    2. 将配置作为根元素添加到此文件。所以你的 common.config 将如下所示。

    <configuration>
      <appSettings>
        <add key="myKey" value="This is the Value"/>
      </appSettings>
    </configuration>
    
    1. 运行加密命令。

      aspnet_regiis.exe -pef appSettings c:\Users\ja\Document\ -prov "RsaProtectedConfigurationProvider"

    2. 打开加密文件并删除配置标签。

    3. 将文件重命名为 Common.config PS:我删除了我在这个帖子上发布的原始cmets。

    【讨论】:

    • 我收到此错误:Unrecognized attribute 'configProtectionProvider'. Note that attribute names are case-sensitive. 在 common.config 文件中是否显示 &lt;appSettings configProtectionProvider="RsaProtectedConfigurationProvider"&gt;
    • 加密后还是加密中?
    • 它加密很好,当我运行程序时出现错误。`
    • 尝试在没有提供程序的情况下运行加密命令。比如 aspnet_regiis.exe -pef appSettings c:\Users\ja\Document\。另外,加密后可以发布文件内容吗?
    • 还是会自动添加configProtectionProvider="RsaProtectedConfigurationProvider"
    【解决方案2】:

    您似乎没有提供完整路径:

    c:\Users\ja\Document\

    C:\Users\ja\Documents\common.config

    如果语法需要目录,Document 仍然缺少's'

    【讨论】:

    • 看起来 path 参数应该指向一个 Web 应用程序。也许将 common.config 移动到应用程序的根目录而不是 Documents 文件夹?
    • 解密 web.config 的方式相同。
    猜你喜欢
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-28
    相关资源
    最近更新 更多