I have a sharepoint webpart running on sharepoint server 2010 site which serves as the team project portal since it is integrated with TFS 2010. The webpart successfully deploys to the site and I am able to see it.
Using the TfsConfigurationServer class I am able to connect to TFS and get a list of all the project collections. If I go 1 step further down I can get a list of all the team projects in each collection. My problem arises when I try to connect to the version control server for a collection. I want to connect to the version control server so I can get a list of the folders/files under that project collection.
TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
try
{
VersionControlServer versionControl = (VersionControlServer)teamProjectCollection.GetService(typeof(VersionControlServer));
TeamProject tp = versionControl.GetTeamProject("MyTeamProject");
RecursionType recursion = RecursionType.Full;
ItemSet itemSet = tp.VersionControlServer.GetItems(tp.ToString(), recursion);
Item[] items = itemSet.Items;
foreach (Item item in items)
{
l = new Label();
l.Text = item.ChangesetId.ToString();
this.Controls.Add(l);
}
}
catch (Exception ex)
{
ex.ToString();
}
The above code fails on the first line after the Try block, the "versioncontrolserver" line. The error says "You are not allowed to change users when re-authenticating." Why is it trying to change users? The user account (mine) has access to both sharepoint and tfs. If I add a WindowsIdentity variable, and run in debug with a breakpoint, I can confirm the webpart runs under my user account. Since it fails on the versioncontrolserver line, it seems to be reauthenticating when it connects to the tfs system. If it's switching accounts, why would it? and what account is it trying to use?