TFS API:如何检查用户是否对项目集合和项目具有管理员权限?

TFS API:如何检查用户是否对项目集合和项目具有管理员权限?,tfs,tfs-sdk,Tfs,Tfs Sdk,我需要检查用户(连接到项目集合)是否是项目集合的administrators组的成员。另外,我需要为一个项目做同样的事情 我需要最正确的方法 目前我正在使用以下方法,但我不确定这是否是一种完美的方法 //Get the IdentityManagementService from the Project Collection IIdentityManagementService LIdentityService = (IIdentityManagementService)ProjectColle

我需要检查用户(连接到项目集合)是否是项目集合的administrators组的成员。另外,我需要为一个项目做同样的事情

我需要最正确的方法

目前我正在使用以下方法,但我不确定这是否是一种完美的方法

//Get the IdentityManagementService from the Project Collection
IIdentityManagementService LIdentityService = (IIdentityManagementService)ProjectCollection.GetService(typeof(IIdentityManagementService));    
//Search for user identity by user name
TeamFoundationIdentity LUserIdentity = LIdentityService.ReadIdentity(IdentitySearchFactor.AccountName, {Username}, MembershipQuery.Expanded, ReadIdentityOptions.None);
//Get Guid of the same Project Collection to use as scope
String Id = ProjectCollection.InstanceId.ToString();
//Get the Administrators group for Project Collection scope *
TeamFoundationIdentity LAdminIdentity = LIdentityService.ReadIdentity(IdentitySearchFactor.AdministratorsGroup, Id, MembershipQuery.Expanded, ReadIdentityOptions.None);

IsAdmin = false;
//Traverse through the groups of the user and check if administrators group is also one of them
foreach (IdentityDescriptor member in LUserIdentity.MemberOf)
{
    if (member.Identifier.Equals(LAdminIdentity.Descriptor.Identifier, StringComparison.CurrentCultureIgnoreCase))
        IsAdmin = true;
}

在一个设置上运行良好,但是在Team Foundation Server的另一个设置中,在获得管理员组时,会出现以下错误。


“Team Foundation身份范围{项目集合的GUID”不存在。“< /P>”您在何处/如何定义<代码> ProjcProjk.StasyNID?这不同于TeamProjectCollections,当然也不同于TFS服务器。错误表示您使用的Guid不存在,因此我希望您使用的Guid来自一台服务器和另一台服务器。是项目集合之间的实例id不同。在函数中,我在项目集合级别搜索Administrators组标识符,因此我必须传递项目集合的实例Id。我已经注意到使用来自同一台服务器的项目集合。但是似乎您在某处切换了TFS服务器实例,而不是ProjectCollection。或者,你的意思是“*这在一个设置上很好,但是在Team Foundation Server的另一个设置上,它会产生以下错误”?你是否考虑过用显示名称(即“代码>项目集合管理员< /代码>”而不是集合的GUID查询群组?@ JAMESTOLL -是的,我尝试使用“Project Collection Administrators”的名称有效。但我不确定“Project Collection Administrators”的名称在其他地区和语言的情况下是否会保持不变,或者是否允许用户更改它。是否有什么方法可以确认这一点。