Accessing encrypted connection string in SharePoint web.config problem
-
venerdì 13 aprile 2012 20:39
I have edited the web.config for my SharePoint iis web application and added the following:
<connectionStrings>
<add name="MyConnectionString" connectionString="Data Source=mysqlserver;network library=dbmssocn;Initial Catalog=mydb;User Id=myuser;Password=somepassword;" providerName="System.Data.SqlClient" />
</connectionStrings>From my web part, I can access the connection string like this:
string lcConnectionString = "";
System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
System.Configuration.ConnectionStringSettings connString;
if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
{
connString = rootWebConfig.ConnectionStrings.ConnectionStrings["MyConnectionString"];
if (connString != null)
lcConnectionString = connString.ConnectionString;
}
Now, I want to encrypt the connection string found in the web.config so I did this:
aspnet_regiis -pef "connectionStrings" "C:\inetpub\wwwroot\wss\VirtualDirectories\443"
This works and the appropriate information is encrypted in the web.config file.
I added the application pool account to have access to decrypt this information like this:
aspnet_regiis -pa "NetFrameworkConfigurationKey" "mydomain\myapppoolaccount"
Now, when I access the SharePoint site, I get the following error:
HTTP 500 Internal Server Error
I enabled verbose logging in Central Administration and used ULS viewer and found this in the log:
"Error=The RSA key container could not be opened."
At this point I am not sure how to proceed. Is there another account that needs to be assigned to have access using aspnet?
Since this is a test environment, I added the farm account to have access too but the error still persists.
Any help is appreciated...
- Modificato davestech venerdì 13 aprile 2012 20:40
Tutte le risposte
-
martedì 17 aprile 2012 02:25Moderatore
Hi davestech,
Please check if identity impersonate is set to true in web.config file and windows authentication is enabled, if so, and it doesn’t work, try to pass “NT Authortity\Authenticated Users” as the account name to check the result, you can refer to the following link for more information:
http://blogs.msdn.com/b/mosharaf/archive/2005/11/17/protectedconfiguration.aspxMore information, how to encrypt configuration sections in asp.net:
http://msdn.microsoft.com/en-us/library/ms998283.aspxThanks,
QiaoQiao Wei
TechNet Community Support
- Contrassegnato come risposta Qiao WeiMicrosoft Contingent Staff, Moderator giovedì 26 aprile 2012 09:38

