run2004
asked on
Please help in encrypting the connection string in the Web.config file using ASP.Net 2.0
Hi,
I have tried a couple of things to encrypt and store the database connection string in Web.config file. Please provide me a working example.
In addition to this if I create a custom sections then what will be the beyst way to encrypt the information in that custom section?
Appreciate your help.
~Run2004
I have tried a couple of things to encrypt and store the database connection string in Web.config file. Please provide me a working example.
In addition to this if I create a custom sections then what will be the beyst way to encrypt the information in that custom section?
Appreciate your help.
~Run2004
ASKER
The above code is in VB.Net. I am looking for the code in C#. Can you please let me know if I need to decrypt the string before making the calls to the database?
I learnt that we need not to decrypt the string. It's automatically decrypted when ASP.Net makes a call to this. Can you conpfirm?
I learnt that we need not to decrypt the string. It's automatically decrypted when ASP.Net makes a call to this. Can you conpfirm?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can modify to add in more webconfig sections.
The usage is just EncryptConfig(True) to encrypt / EncryptConfig(False) turn back to clear text
Protected Sub EncryptConfig(ByVal bEncrypt As Boolean)
Dim path = "YourWebConfigPath"
Dim config As Configuration = WebConfigurationManager.Op
Dim appSettings As ConfigurationSection = config.GetSection("connect
If bEncrypt Then
appSettings.SectionInforma
Else
appSettings.SectionInforma
End If
config.Save()
End Sub