Tuesday, July 17, 2012

Encrypt/Decrypt - Connection Strings in Web.config

To encrypt the connection string section follow the steps,
1. Go to Start -> Programm Files -> Microsoft Visual Studio 2005 -> Visual Tools
    -> Microsoft Visual Studio 2005 Command Prompt

2. Type following command,
    aspnet_regiis.exe -pef connectionStrings C:\Projects\DemoApplication
    -pef indicates that the application is built as File System website.  The second argument is the name of configuration section needs to be encrypted. Third argument is the physical path where the web.config file is located.
   If you are using IIS base web site the command will be,
   aspnet_regiis.exe -pe connectionStrings -app “/DemoApplication”
 -pe indicates that the application is built as IIS based site. The second argument is the name of configuration section needs to be encrypted. Third argument “-app” indicates virtual directory and last argument is the name of virtual directory where application is deployed.   
Now to decrypt the configuration section in web.config file use following command,
For File System Application,

aspnet_regiis.exe -pdf “connectionStrings” C:\Projects\DemoApplication
For IIS based Application
aspnet_regiis.exe -pd “connectionStrings” -app “/DemoApplication”
You can encrypt all the sections of web.config file except following using the method I displayed in this article,










No comments: