-->

在连接到TFS使用TFS API认证失败(authentication failed while c

2019-08-04 00:46发布

我面临着一个奇怪的issue.I要使用TFS API programmitcally连接TFS服务器。 即使给予适当authentcaion crediatials后是failing.But,如果我做手工在浏览器中它得到连接输入TFS服务器名称。

码:

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

请建议。

Answer 1:

您是否尝试过做这种方式..

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


Answer 2:

一个简单的方法做,这是对“Syetem.Net”命名空间添加到您的代码,然后使用“CredentialCache”对象。 使用“的DefaultCredentials”将与活跃用户的凭据进行身份验证。

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


Answer 3:

对于您的问题,通常你会得到这样的错误:

对于失败的原因包括: - 名称,端口号或协议在Team Foundation Server不正确。 - 在Team Foundation Server处于脱机状态。 - 密码已过期或不正确。

你的问题的根本原因是URI应该结束了集合名称 。 因此,解决将是,改变“ http://10.112.205.145:8080/tfs ”到“ http://10.112.205.145:8080/tfs/ %YourCollectionName%”,那么它将工作! :-)



文章来源: authentication failed while connecting to tfs using tfs api