Wednesday, April 22, 2009

Failed to decrypt the Web.config in asp.net

After encrypting the appSettings in web.config file using the command

aspnet_regiis -pef "appSettings" "c:\<appfolder>"
you may recieve the following error

"Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened."

or the site will not work since it cannot read/decrypt the web.config contents (connection string or any similiar data).

Resolution
This is because your ASP.NET application identity does not have access to the .NET Framework configuration key store. To give rights use the following command

aspnet_regiis -pa "NetFrameworkConfigurationKey" "<application pool identity account>"

Hope this helps..