我正在尝试建立VSSconnection,以使用客户端库从我们的TFS中获取一些数据。我的认证有问题。构造我的VSS凭证时,凭证为空。当我建立与图书馆的连接时,该应用会崩溃:
TF400813:用户[我的计算机的主机名'无权访问此资源。
代码:
private IPrincipal _user;
public VssConnection GetClient(Uri uri)
{
WindowsIdentity id = (WindowsIdentity) _user.Identity;
WindowsImpersonationContext impersonationContext;
impersonationContext = id.Impersonate();
WindowsIdentity newid = WindowsIdentity.GetCurrent();
string name = newid.Name;
//above gets my user name but below does not, and I don't know how to set it.
var credentials = new VssCredentials();
return new VssConnection(uri,credentials);
}
public List<TeamProjectCollectionReference> GetCollectionNodes(List<string> selectedCollectionsList = null)
{
var client = GetClient(TfsUri);
/*crashes here*/ var collectionClient = client.GetClient<ProjectCollectionHttpClient>();
IEnumerable<TeamProjectCollectionReference> collectionNodes = collectionClient.GetProjectCollections().Result;
....