[英]How to retrieve DirectoryEntry from a DirectoryEntry and a DN
我有一个表示用户的DirectoryEntry
对象。 从DirectoryEntry.Properties
集合中,我正在检索"manager"
属性,该属性将为用户的经理提供一个专有名称(“DN”)值。
我可以从这两个对象中检索管理器的DirectoryEntry
对象吗? 如果是这样,怎么样?
我正在设想像DirectoryEntry.GetEntryFromDN(dnManager);
,但我找不到类似的电话。
为了澄清,DirectoryEntry和DN是我拥有的唯一信息。 我无法实例化新的DirectoryEntry
因为那时我必须使用默认目录和凭据,或者具有目录名称/端口和用户名/密码。
DirectoryEntry User = YourPreExistingUser();
string managerDN = User.Properties["manager"][0].ToString();
// Browse up the object hierarchy using DirectoryEntry.Parent looking for the
// domain root (domainDNS) object starting from the existing user.
DirectoryEntry DomainRoot = User;
do
{
DomainRoot = DomainRoot.Parent;
}
while (DomainRoot.SchemaClassName != "domainDNS");
// Use the domain root object we found as the search root for a DirectorySearcher
// and search for the manager's distinguished name.
using (DirectorySearcher Search = new DirectorySearcher())
{
Search.SearchRoot = DomainRoot;
Search.Filter = "(&(distinguishedName=" + managerDN + "))";
SearchResult Result = Search.FindOne();
if (Result != null)
{
DirectoryEntry Manager = Result.GetDirectoryEntry();
}
}
您可以创建一个新的DirectoryEntry实例,将DN作为参数提供,然后尝试绑定(例如,通过刷新属性)。
DirectoryEntry e = new DirectoryEntry(dn,“u”,“p”);
e.RefreshCache();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.