如何加密config文件Asp.net [英] How to encrypt .config file Asp.net

查看:127
本文介绍了如何加密config文件Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要加密common.config,而不是Web.config文件。 Common.config是在不同的位置比web.config中。 web.config文件连接到common.config。

web.config中:

 <文件的appSettings =C:\\用户\\ JA \\文档\\ common.config>
    <添加键=网页:版本值=3.0.0.0/>
    <添加键=网页:启用VALUE =FALSE/>
    <添加键=ClientValidationEnabledVALUE =真/>
    <添加键=UnobtrusiveJavaScriptEnabledVALUE =真/>
< /的appSettings>

common.config:

 <&的appSettings GT;
    <添加键=的myKeyVALUE =这就是价值/>
< /的appSettings>`

这适用于web.config文件:

  ASPNET_REGIIS.EXE -pef的appSettings C:\\用户\\ JA \\桌面\\测试\\ web应用程序\\ web应用-provRsaRpotectedConfigurationProvider

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

ASPNET_REGIIS.EXE -pef的appSettings C:\\用户\\ JA \\文档\\ -provRsaRpotectedConfigurationProvider

我得到这个错误:

 对物理路径的配置C:\\ \\ JA \\文档\\用户无法打开


解决方案

我找到的解决方法来解决这个问题。希望它帮助。


  1. 重命名common.config到web.config中暂时的。


  2. 添加配置,根元素到此文件。所以,你的common.config看起来就像如下:


 <结构>
  <&的appSettings GT;
    <添加键=的myKeyVALUE =这就是价值/>
  < /的appSettings>
< /结构>

<醇开始=3>

  • 运行加密命令。

    ASPNET_REGIIS.EXE -pef的appSettings C:\\用户\\ JA \\文档\\ -provRsaProtectedConfigurationProvider


  • 打开加密的文件,并删除配置标签。


  • 重命名文件Common.config
    PS:我删除张贴在这个线程我原来的意见


  • I want to encrypt common.config, not the Web.config file. Common.config is in a different location than the web.config. The web.config file is connected to the 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>`
    

    This works for the web.config file:

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

    But when I try to encrypt the common.config file:

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

    I get this error:

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

    解决方案

    I found workaround to solve this issue. Hope it helps.

    1. Rename your common.config to web.config temporarily.

    2. Add configuration as root element to this file. So your common.config will look like as follows.

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

    1. Run encrypt command.

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

    2. Open encrypted file and remove Configuration tags.

    3. Rename file to Common.config PS: I deleted my original comments posted on this thread.

    这篇关于如何加密config文件Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆