给定一个代表 Active Directory 中用户的 GUID,我如何使用它来确定使用 C# 的用户的“专有名称”?
GUID 是在我们的应用程序中使用 directoryEntry.Guid 检索的; MSDN Link
最佳答案
当您明确表示要搜索的是 GUID 时,试试这个:
using System;
using System.DirectoryServices.AccountManagement;
public static class DomainHelpers
{
public string GetDistinguishedName(string domain, string guid)
{
var context = new PrincipalContext(ContextType.Domain, domain);
var userPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.Guid, guid);
return userPrincipal.DistinguishedName;
}
}
我已经将它与 IdentityType.Name
一起使用,所以不能确定它是否适用于 IdentityType.Guid
,但值得一试。
关于c# - 给定一个代表 Active Directory 中用户的 GUID,我将如何使用它来确定专有名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3503143/