4

I know I can do this to encrypt connection strings in a web site that is already deployed:

aspnet_regiis -pe connectionStrings

I can also encrypt connection strings in a web site before it is deployed by doing this:

aspnet_regiis -pef connectionStrings .\WebApplication1

I also know how to make my own RSA key, install it on several computers, and set up an encryption provider for that key, so I can encrypt it on one machine and publish it on another:

aspnet_regiis -pef connectionStrings .\WebApplication1 -prov MyProvider

I can even tell MSBuild to encrypt the connection strings for me during deployment by adding a line to the .pubxml file (https://msdn.microsoft.com/en-us/library/ee942158%28v=vs.110%29.aspx#encrypt_webconfig).

But what I really need to do is this:

  1. create the web site source code and save it in source control with the connection strings decrypted;
  2. build the web site, transforming the web.config file with web.debug.config or web.release.config;
  3. encrypt the connection strings in the transformed web.config using my custom encryption provider;
  4. and then publish it

all from an automated process. Note: I can't encrypt the connection strings first and then build the web site, because I have to transform the web.config file before encrypting it. I don't want to publish the web site first and then encrypt the connection strings, because I don't want the decrypted connection strings to be on the web server even for a brief time. I want to encrypt the connection strings during the deploy process, but with my own encryption provider. How can I do that? It's got to be possible. Any combination of msbuild commands, msdeploy commands, and .pubxml file settings would be acceptable.

I've tried searching for how to do this -- I really have -- but I can't find a comprehensive reference for msbuild.exe / msdeploy.exe / *.pubxml ANYWHERE. (That's a separate question.)

Daniel
  • 155
  • 1
  • 8

0 Answers0