Use the following steps to encrypt/decrypt the connectionStrings section in a web.config file:

  1. Open the web.config file and write down the “targetFramework” attribute value in the <compilation> section. (ex: 4.0)
  2. Start -> All Programs -> Accessories -> (right click) Command Prompt -> Run as administrator -> Yes
  3. Enter “cd\” to get to the root folder
  4. In the following step, replace “MyTargetFramwork” with the available version number that best matches the “targetFramework” value you wrote down in step 1. (ex: v4.0.30319)
  5. Enter “cd Windows\Microsoft.NET\Framework\MyTarketFramework\”
  6. To choose a web.config file based on file location, skip to step 7 and 8; To choose a web.config file based on IIS web application path, skip to step 9 and 10.
  7. To encrypt the connectionStrings section, enter: aspnet_regiis –pef “connectionStrings” C:\inetpub\wwwroot\MyWebApplicationPath
  8. To decrypt the connectionStrings section, enter: aspnet_regiis –pdf “connectionStrings” C:\inetpub\wwwroot\MyWebApplicationPath
  9. To encrypt the connectionStrings section, enter: aspnet_regiis –pe “connectionStrings” – app “/MyWebApplicationPath
  10. To decrypt the connectionStrings section, enter: aspnet_regiis –pd “connectionStrings” – app “/MyWebApplicationPath

The <connectionStrings> section of the web.config file should be encrypted/decrypted now.

Advertisements