简体   繁体   English

使用 tfs api 将工作项插入到 tfs 中

[英]insert work item into tfs using tfs api

I am building a Web page to insert TFS Work Items into TFS using TFS API.我正在构建一个网页,以使用 TFS API 将 TFS 工作项插入到 TFS 中。

I am using my credentials to connect to TFS Server.我正在使用我的凭据连接到 TFS 服务器。

Each time someone creates a TFS Work item using the TFS Web page, it creates a Work Item under my name ,since I was the one connected to the TFS Server.每次有人使用 TFS 网页创建 TFS 工作项时,它都会以我的名字创建一个工作项,因为我是连接到 TFS 服务器的人。 Is there a way I can Create a Work Item with the User logged into my web application and created the work Item ?有没有一种方法可以在用户登录到我的 Web 应用程序并创建工作项的情况下创建工作项?

I have access to the Users name but not to the users password我可以访问用户名但不能访问用户密码

protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
        Uri url = new Uri("url");

            NetworkCredential nc = new NetworkCredential();

            TfsTeamProjectCollection coll = new TfsTeamProjectCollection(url, nc);

            coll.EnsureAuthenticated();

            WorkItemStore workItemStore = coll.GetService<WorkItemStore>();
            Project teamproject = workItemStore.Projects["ABC"];
            WorkItemType workItemType = teamproject.WorkItemTypes["Issue"];

            WorkItem wi = new WorkItem(workItemType);

            wi.Title = ((TextBox)FormView1.FindControl("txtTaskTitle")).Text;   

            wi.Save();

        }

Can you please tell me what I can do to have the name of the Person who logged into the application as the one who created the TFS Work Item ?你能告诉我我能做些什么来让登录应用程序的人的名字成为创建 TFS 工作项的人吗?

I also tried the following :我还尝试了以下方法:

       Uri url = new Uri("url");

        var collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(url);
        var workItemStore = new WorkItemStore(collection, WorkItemStoreFlags.BypassRules);

        Project teamproject = workItemStore.Projects["ABC"];
        WorkItemType workItemType = teamproject.WorkItemTypes["Issue"];

        WorkItem wi = new WorkItem(workItemType);

        string s = "Name";
        wi.Fields["System.CreatedBy"].Value = s;

        wi.Title = "Test Item";
        wi.Save();

You could try setting the Created By field:您可以尝试设置创建者字段:

wi.Fields["System.CreatedBy"].Value = "TfsService";

Per the answer on this thread , you may need to be a member of the Project Collection Service Accounts.根据此线程上的答案,您可能需要成为 Project Collection Service Accounts 的成员。

Also, see this thread .另外,请参阅此线程 It looks like you may only be able to modify the Created By field on the first revision... Or, you can try creating the WorkItemStore (instead of using the service) and using this flag: WorkItemStoreFlags.BypassRules看起来您可能只能在第一次修订时修改 Created By 字段...或者,您可以尝试创建 WorkItemStore(而不是使用服务)并使用此标志: WorkItemStoreFlags.BypassRules

Try this:尝试这个:

TfsTeamProjectCollection coll = new TfsTeamProjectCollection(url,CredentialCache.DefaultCredentials);

Get rid of the whole Network credential thing.摆脱整个网络凭据的东西。

You need to do two things.你需要做两件事。 First follow Etienne's suggestion and either remove the credentials or pass the default.首先按照 Etienne 的建议删除凭据或传递默认值。

Second you need to enable "impersonation" in your web application:http://msdn.microsoft.com/en-us/library/134ec8tc(v=vs.100).aspx其次,您需要在您的 Web 应用程序中启用“模拟”:http ://msdn.microsoft.com/en-us/library/134ec8tc(v=vs.100).aspx

That works fine if your run your web application on your TFS server.如果您在 TFS 服务器上运行您的 Web 应用程序,那效果很好。 However if you want to run it elsewhere you will also need a kerberos token to allow you to pass through the credentials to the TFS server.但是,如果您想在其他地方运行它,您还需要一个 kerberos 令牌以允许您将凭据传递到 TFS 服务器。 This is often called double-hop authentication.这通常称为双跳身份验证。 To get it working you have to do some giggery-pokery with Active Directory and setup Service Principal Names (SPN) for the account that you run your website under.要使其正常工作,您必须对 Active Directory 进行一些操作,并为您运行网站的帐户设置服务主体名称 (SPN)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM