I have a limited access to the TFS server,so I intended to use a administrator account in the code to connect to the server.I found that when I deploy the service on a computer which does not join into the domain,it works just fine,but when deploy the service on a domain-joined computer,it uses integrated credential.Great thanks for help!Following is my code.
Uri tfsUri = Common.Helper.GetCollectionUri();
UserCredential userCredential = new UserCredential("administrator", "pass@word1", "zanewill.net");
TfsTeamProjectCollection col = new TfsTeamProjectCollection(tfsUri, userCredential);
TeamFoundationIdentity identity;
col.EnsureAuthenticated();
col.GetAuthenticatedIdentity(out identity);
I want the credential of administrator,but the identity always be the credential of 'zanewill' which is a limited domain account.
the class of UserCredential is like following public class UserCredential : ICredentialsProvider { private NetworkCredential networkCredential;
public UserCredential(string userName, string password, string domain) {
networkCredential = new NetworkCredential(userName, password, domain);
}
public System.Net.ICredentials GetCredentials(Uri uri, System.Net.ICredentials myCredentials) {
return networkCredential;
}
public void NotifyCredentialsAuthenticated(Uri uri) {
}
}
I use NetworkCredential like the following code, and it works, I don't know why.
Uri tfsUri = Common.Helper.GetCollectionUri();
var networkCredential = new NetworkCredential("administrator", "pass@word1", "zanewill.com");
TfsTeamProjectCollection col = new TfsTeamProjectCollection(tfsUri,networkCredential);
TeamFoundationIdentity identity;
col.EnsureAuthenticated();
col.GetAuthenticatedIdentity(out identity);