ASP.Net MVC: Encrypting the connection string inside the web.config.

As we all know that the connection string is the vital part of the any application, also so much vulnerable if we have mentioned it as a simple string inside the web.config. So we want that to be encrypted. But to do that there are so many method by which you an do it. ,anually also you can encrypt that by your own logic and decrypt based on that during the creating the conection string or to pass on to the entity framework. 

but i found a easiest way to do that, which by default come with .net Framework. aspnet_regiis is the command help us in that. you need to encrypt connection string during the deployment to production. not needed during development, if you don't want to hide the sql info from your developers. Also after encrypting it you can decrypt the same to see the original values.

Use aspnet_regiis. In command line browse to (usually):
cd C:\WINDOWS\Microsoft.NET\Framework\respective version folder
or 
you can open the command prompt from Visual studio tools folder from the start menu
and type:
aspnet_regiis -pef "sectionName of web.config" "physical path to web.config file" - to encrypt
aspnet_regiis -pdf "sectionName of web.config" "physical path to web.config file" - to decrypt
For example:


aspnet_regiis -pef "connectionStrings" "D:\projects\HelloWorldProject"

enjoy the secrecy.

Comments

Popular posts from this blog

LINQ: Using int.TryParse() within a LINQ where clause

ASP.Net MVC: Configuring asp.net session state in SQL Server.

IIS: Publish Project to remote IIS with Web Deploy.