【问题标题】:Authenticating on TFS 2010在 TFS 2010 上进行身份验证
【发布时间】:2016-09-11 20:10:54
【问题描述】:

我在 MS Team Foundation Server 上以特定用户身份进行身份验证时遇到问题。在旧版本中,它看起来像:

teamFoundationCredential = new System.Net.NetworkCredential("<USERNAME>", "<PASSWORD>", "<DOMAIN>");

TeamFoundationServer tfs = new TeamFoundationServer("http://mars:8080/", teamFoundationCredential);

谁能告诉我 2010 版的等效版本。到目前为止,我有:

ICredentialsProvider cred = null;

tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://asebeast.cpsc.ucalgar.ca:8080/tfs/DefualtCollection"));

tfs.EnsureAuthenticated();

谢谢

【问题讨论】:

    标签: tfs


    【解决方案1】:

    对于 TFS 2010,请使用以下内容:

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

    【讨论】:

    • 请注意,如果我删除了用户名的“domain_par”部分,这对我在非域服务器上有效。
    • 另外:你不需要 NetworkCredential("username","password","domain") 而不是 NetworkCredential("username\\domain","password)。它对我来说是第一种方式,但不是第二个。
    • 我认为正确的语法是... TfsTeamProjectCollection collection = new TfsTeamProjectCollection( new Uri(@"asebeast.cpsc.ucalgar.ca:8080/tfs/DefualtCollection"), new System.Net.NetworkCredential("domain_name\\user_name", "pwd" ));
    【解决方案2】:

    我也遇到了同样的问题。上面的解决方案对我不起作用,真的不知道为什么。我不断收到演员表异常。 花了一天时间试图解决这个问题 - 所以我想我会分享我目前解决这个问题的方法。 我创建了自己的实现 ICredentialsProvider 的内部类 - 如下:

    private class MyCredentials : ICredentialsProvider
    {
        private NetworkCredential credentials;
        #region ICredentialsProvider Members
        public MyCredentials(string user, string domain, string password)
        {
            credentials = new NetworkCredential(user, password, domain);
        }
    
        public ICredentials GetCredentials(Uri uri, ICredentials failedCredentials)
        {
           return credentials;
        }
    
        public void NotifyCredentialsAuthenticated(Uri uri)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    }
    

    然后我将其实例化并传递如下:

    MyCredentials credentials = new MyCredentials(UserName, Password, Domain);
    TfsTeamProjectCollection configurationServer =
        TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
            new Uri(tfsUri), credentials);
    

    请注意,我还没有实现 NotifyCredentialsAuthenticated - 不确定这实际上做了什么,所以将 NotImplementedException 留在了那里,这样我就可以在它被调用时捕捉到它,到目前为止还没有发生。现在已成功连接到 TFS。

    【讨论】:

    • 您可能只需要执行 new NetworkCredential("username","password","domain") 而不是 NetworkCredential("username\\domain","password)
    【解决方案3】:

    我在使用这种方法连接到我们的旧 TFS 2008 服务器时也遇到了一些问题,但解决我的问题的方法非常简单:

    首先我将 TFS Url 定义为:

    private const string Tfs2008Url = @"http://servername:8080/tfs/";
    static readonly Uri Tfs2008Uri = new Uri(Tfs2008Url);
    

    URL 中使用的路径是我们通过 VisualStudio 连接时使用的路径,所以我认为这在 API 调用中必须相同,但是当我尝试通过以下身份验证使用它时,我得到了 TF31002 / 404错误:

    var collection = new TfsTeamProjectCollection(Tfs2008Uri,new NetworkCredential("AdminUser","password","domain_name"));
    collection.EnsureAuthenticated();
    

    但是当我将 Url 更改为 TFS 根目录时,它通过了身份验证!

    private const string Tfs2008Url = @"http://servername:8080/";
    static readonly Uri Tfs2008Uri = new Uri(Tfs2008Url);
    

    不知道这是否对任何人有帮助,但它确实对我有用!

    【讨论】:

      【解决方案4】:

      这对我来说效果很好:

      _tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
      _tfs.ClientCredentials = new TfsClientCredentials(new WindowsCredential(new NetworkCredential("myUserName", "qwerty_pwd", "myDomainName")));
      _tfs.EnsureAuthenticated();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-23
        • 1970-01-01
        • 2015-09-23
        • 2016-02-04
        • 2020-10-21
        • 2018-11-01
        • 2010-11-11
        • 2011-04-30
        相关资源
        最近更新 更多