authentication failed while connecting to tfs using tfs api

雨燕双飞 提交于 2019-12-04 05:37:39

问题


I am facing a strange issue.I want to connect tfs server using tfs api programmitcally. Even after giving proper authentcaion crediatials it is failing.But if I do it manually by typing tfs server name in browser its got connected.

code:

TeamFoundationServer tfs = new TeamFoundationServer(new Uri("http://10.112.205.145:8080/tfs"),  new NetworkCredential(@"usrname", "pwd", "domain"));
tfs.EnsureAuthenticated()

Please suggest.


回答1:


Have you tried doing it this way..

TfsTeamProjectCollection collection = new TfsTeamProjectCollection(
    new Uri(http://server:8080/tfs/DefaultCollection,
    new System.Net.NetworkCredential("domain_name\\user_name", "pwd"));
collection.EnsureAuthenticated();



回答2:


A simple way to do this is to add the "Syetem.Net" namespace to your code and then use the "CredentialCache" object. Using "DefaultCredentials" will Authenticate with the credentials of the active user.

// connect to the collection
using (TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection("http://server:8080/tfs/DefaultCollection", CredentialCache.DefaultCredentials))
            { 
                //Do Stuff here 
            }



回答3:


For your problem, normally you get an error like:

Possible reasons for failure include: - The name, port number, or protocol for the Team Foundation Server is incorrect. - The Team Foundation Server is offline. - The password has expired or is incorrect.

The root cause of your problem is that the URI should be ended up with the collection name. So the fix would be, to change "http://10.112.205.145:8080/tfs" to "http://10.112.205.145:8080/tfs/%YourCollectionName%", then it will work! :-)



来源:https://stackoverflow.com/questions/13854147/authentication-failed-while-connecting-to-tfs-using-tfs-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!