2015-01-16 26 views
0

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

的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" 

但是,当我试图加密常用.config文件:

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

我得到这个错误:

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

回答

0

它看起来并不像你所提供的完整路径:

C:\用户\ JA \文档\

VS

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

如果synt ax需要目录,Document仍然缺少's'

+0

不行,它仍然不起作用。 – User765876

+0

它看起来像路径参数应该指向一个Web应用程序。也许将common.config移动到应用程序的根目录而不是Documents文件夹? – David

+0

也不起作用。 – User765876

1

我找到了解决此问题的解决方法。希望能帮助到你。

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

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

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

    ASPNET_REGIIS.EXE -pef的appSettings C:\用户\ JA \文献\ -prov “RsaProtectedConfigurationProvider”

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

  • 将文件重命名为Common.config PS:我删除了在此主题上发布的原始评论。

  • +0

    我收到此错误:'无法识别的属性'configProtectionProvider'。请注意,属性名称区分大小写。配置文件是它说'' – User765876

    +0

    加密或加密后? –

    +0

    当我运行出现错误的程序时,它会很好地加密。“ – User765876