Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypting web.config on shared hosting

I want to encrypt the connection strings in a web.config file in a shared hosting environment.

I have read most of the articles on MSDN on the subject (http://msdn.microsoft.com/en-us/library/53tyfkaw.aspx) and concluded that I need to use RSAProtectedConfigurationProvider so that I can export the config file with key container to our shared hosting provider. However, when I do this I get an error "The RSA key container could not be opened." I assume this is because I need to grant access to the aspnet account to the key container, but this is done using the aspnet_regiis tool which I can't use as I'm on a shared host.

So I tried programatically encrypting it on application start in the global.asax, but I get a permission error when saving the file - "An error occurred loading a configuration file: Access to the path 'C:\Inetpub\xxx\yyy\3acp98k.tmp' is denied. Shared hosting restriction, I assume.

I can't run the aspnet_regiis tool as its a shared hosting environment.

Does anyone have any ideas as to how I might encrypt the connection strings?

like image 645
Gais Avatar asked Nov 05 '22 19:11

Gais


2 Answers

You just need to make web.config writable. Shared hosts either give full access to the IIS user or give you some web-based tool, in you file manager maybe, to edit permissions. You don't need to run aspnet_regiis.

like image 179
Parsa Avatar answered Nov 12 '22 11:11

Parsa


I see nothing has been marked as an answer so I will assume that you didnt get a solution to this. Just an idea - but if the only problem is that your application doesnt have write access to your config file (hint: your FTP account has write permissions!) - just write an ASPX page that reads the connection string settings, and displays the encrypted Xml (you might want to put it in a password protected location).

Then all you have to do is:

  1. create an unencrypted web.config
  2. upload it
  3. visit your 'display encrypted connectionstrings webpage'
  4. copy and paste the encrypted data in to your local web.config
  5. upload the web.config again with the new encrypted settings!
like image 35
Adam Avatar answered Nov 12 '22 12:11

Adam