How to encrypt a file linked to a web.config

2019-09-16 16:14发布

I have a web.config file that links to a common.config file. common.config is being used by multiple applications. I used the aspnet_regiis.exe, but that only encrypts the web.config file. How can i encrypt the common.config file?

web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings file="C:\Users\naem\Documents\common.config" />
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>

common.config file:

<?xml version="1.0" encoding="utf-8"?>
  <appSettings>
    <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" />
    <add key="myKey" value="This is the Value!!!!"/>
  </appSettings>

2条回答
何必那么认真
2楼-- · 2019-09-16 16:17

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="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="myKey" value="This is the Value!!!!"/>
  </appSettings>
</configuration>
  1. Run encrypt command.

    aspnet_regiis.exe -pef appSettings "C:\Users\naem\Documents"

  2. Open encrypted file and remove Configuration tags.

  3. Rename file to Common.config

查看更多
【Aperson】
3楼-- · 2019-09-16 16:32

I don't have the rep to comment on the original post, but this looks like a duplicate of How to encrypt .config file Asp.net

查看更多
登录 后发表回答