How to encrypt .config file Asp.net

痴心易碎 提交于 2019-12-25 04:09:08

问题


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

回答1:


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.




回答2:


It doesn't look like you supplied the full path:

c:\Users\ja\Document\

vs

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

If the syntax requires the directory, Document is still missing the 's'



来源:https://stackoverflow.com/questions/27991421/how-to-encrypt-config-file-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!