Saturday, May 4, 2013

Encrypting Connection strings in ASP.NET

 To secure your connection string you can easily encrypt your connectionStrings section of the web.config.

Open command prompt from visual studio tools menu in startup menu, Run as Administrator



Then print, if you use website on local IIS
aspnet_regiis -pe "connectionStrings" -app "/websitename"

Example:


Or if you are using a web application use
aspnet_regiis.exe -pef “connectionStrings”   "C:\path to application on local disk"

to decrypt use 
aspnet_regiis -pd "connectionStrings" -app "/websitename"

Or

aspnet_regiis.exe -pdf “connectionStrings”   "C:\path to application on local disk"

This can be applied to other sections of the web.config.

But note that if you will host your application on a shared host this will not be useful at all and it will not work.

You can use it on a dedicated server or your local server.


Thanks,
Nerdy Geeky J!

1 comment: