-1

It is possible to encrypt the <connectionStrings> section in the web.config file, and deploy it to a web server? On the web server I cannot execute .exe files because it is a public web server (pay monthly).

Daniel Gray
  • 1,697
  • 1
  • 21
  • 41
Joel
  • 65
  • 1
  • 10

1 Answers1

0

Two options that I see are:

  1. If you have no choice, then you could try to encrypt the connection string values when storing them and then decrypt them when retrieving them (you would need additional cryptographic code to do this, related info in this question)

  2. If you are somehow able to execute commands (from the command prompt) on the server, then follow the steps outlined in this article to encrypt the file (on your PC):

  1. Open command prompt with Adminstrator rights.

  2. Change folders: cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

  3. Encrypt the web config file: ASPNET_REGIIS -pef "connectionStrings" "C:\path/to/webConfig"

You will be able to directly access the decrypted value via the ConfigurationManager:

string ConnString = ConfigurationManager.ConnectionStrings[1].ToString();

You must execute the command on the server, as if you move the Web.config to another machine, the file will be impossible to decrypt, since the keys are stored within the server itself.

Community
  • 1
  • 1
Daniel Gray
  • 1,697
  • 1
  • 21
  • 41