Hello,
I am using VS 2013 to create a solution in SharePoint 2013 to access the TFS 2013 WIT. When I want to make a connection to the TFSStore I get following error: Access to the registry key 'HKEY_CURRENT_USER\Software\Microsoft\VSCommon\12.0\ClientServices\TokenStorage\VisualStudio' is denied.
This is my code:
public static bool ValidateTFSConnection(string TfsConnectionURL, SecureStoreCredentialCollection TfsUser, out string errormessage) { errormessage = null; WorkItemStore wistore = null; try { wistore = ConnectToTFS(TfsConnectionURL, TfsUser); } catch(Exception ex) { errormessage = ex.Message; } return (wistore != null ? true : false); }
static WorkItemStore ConnectToTFS(string TFSConnectionURL, SecureStoreCredentialCollection TfsUser)
{
TfsTeamProjectCollection tfs;
if (TfsUser == null)
{
//Uri uri = new Uri("http://tempuri.org/");
//ICredentials credentials = CredentialCache.DefaultCredentials;
//NetworkCredential cred = credentials.GetCredential(uri, "Basic");
//NetworkCredential cred = CredentialCache.DefaultNetworkCredentials;
tfs = new TfsTeamProjectCollection(new Uri(TFSConnectionURL), System.Net.CredentialCache.DefaultNetworkCredentials);
//tfs = new TfsTeamProjectCollection(new Uri(TFSConnectionURL)); //, cred);
}
else
{
string user = DecryptSecureString(TfsUser.First(x => x.CredentialType == SecureStoreCredentialType.WindowsUserName).Credential);
string pass = DecryptSecureString(TfsUser.First(x => x.CredentialType == SecureStoreCredentialType.WindowsPassword).Credential);
tfs = new TfsTeamProjectCollection(new Uri(TFSConnectionURL), new NetworkCredential(user, pass));
}
/*case 1:
if (HttpContext.Current == null) return null;
var baseUserTpcConnection = new TfsTeamProjectCollection(new Uri(TFSConnectionURL));
var ims = baseUserTpcConnection.GetService<IIdentityManagementService>();
var identity = ims.ReadIdentity(
IdentitySearchFactor.AccountName,
HttpContext.Current.User.Identity.Name,
MembershipQuery.None,
ReadIdentityOptions.None);
tfsCred = identity.Descriptor;
tfs = new TfsTeamProjectCollection(new Uri(TFSConnectionURL), tfsCred as IdentityDescriptor);
break;*/
tfs.EnsureAuthenticated();
var wistore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
//Log("ConnectToTFS", TFSConnectionURL);
return wistore;
}
tfs.EnsureAuthenticated(); is the part that returns the exception.
Ronald.
Ronald Put