1. web.config中ConnectionString aspnet_iis加密

  web.config路径:E:\Projects\Libing.Web\web.config

<connectionStrings>
<add name="DBConnectionString" connectionString="Data Source=.;User ID=sa;Password=1;Initial Catalog=DB;Persist Security Info=True;" />
</connectionStrings>

  aspnet_iis加密connectionString:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pef "connectionStrings" "E:\Projects\Libing.Web"
C:\Users\libi>C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pef "connectionStrings" "E:\Projects\Libing.Web"
Microsoft (R) ASP.NET RegIIS 版本 4.0.30319.0
用于在本地计算机上安装和卸载 ASP.NET 的管理实用工具。
版权所有(C) Microsoft Corporation。保留所有权利。
正在加密配置节...
成功!
<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>QHf/c44+ATukJ2ZPqULQPs4Llu7JcUnvgekiNl/ABT+be5W38eUJO0zgM9oN6MvoIsd8BDHAPOXBsr2Sqj/4hA6n2KKUrPlb9tMzyafFL9nUmrs0oCJSLd+mCI2ldrhSc1uTV0XBP35bvLm2VPXRxAXDhvvxq8qnX54Oosq0QB8DGbwdT64hb2xzrWiWXoyw7+HfvK8jLZ9XFhSHXk7/OQiMZfyRp8Iqkt3+KeycjWhm0aU2HPFdJD5vcnW+fWCtbP3wwO9JrD5OW0OI9zWEV40qpaKzLkQLNUCNLRsJI6K78L0xBC25CEnC3fMmRYdHjSwXmAZYRzZu+0jt+f+ZiQ==</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>KMnJpDpH3+qpTmE0bqQSm72zNhopKQqmPdrxZoj3p4CV7ZxQTZEZhZ7EH2KFHjIy6WufonggfqO6m0jGjTO7NgqkwRZL/fo+Od9gR7xnIc8mIedFnJNEXWb4SkwZ+Lb5U1LsmsIXYacr6jA0ZbQVyWjcK+jH5yO2gWTYQdf2MR3AVwMXzUiU2KH40x3OcZMVd4zrjIS71SnqJ/JC73X1WlmoeaRpzlZfKdx+IySt37qeacHOUtHObUG4VDpfv3JV</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>

  aspnet_iis解密connectionString:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pdf "connectionStrings" "E:\Projects\Libing.Web"
C:\Users\libi>C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pdf "connectionStrings" "E:\Projects\Libing.Web"
Microsoft (R) ASP.NET RegIIS 版本 4.0.30319.0
用于在本地计算机上安装和卸载 ASP.NET 的管理实用工具。
版权所有(C) Microsoft Corporation。保留所有权利。
正在解密配置节...
成功!

2. web.config中AppSettings独立文件

  Configs/AppSetting.config:(AppSetting.config存放Configs文件夹中)

<?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="AppVersion" value="1.0"/>
</appSettings>

  web.config:

<appSettings configSource="Configs\AppSettings.config"></appSettings>

  读取配置:

System.Configuration.ConfigurationManager.AppSettings["AppVersion"]
05-06 19:08