首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从DirectoryEntry和DN检索DirectoryEntry

如何从DirectoryEntry和DN检索DirectoryEntry
EN

Stack Overflow用户
提问于 2011-04-07 04:51:17
回答 2查看 14.5K关注 0票数 6

我有一个表示用户的DirectoryEntry对象。从DirectoryEntry.Properties集合中,我将检索"manager"属性,该属性将为我提供用户经理的可分辨名称("DN")值。

我可以仅从这两个对象中检索管理器的DirectoryEntry对象吗?如果是这样的话,是怎么做的?

我正在设想类似于DirectoryEntry.GetEntryFromDN(dnManager);的东西,但我找不到类似的调用。

为了澄清,DirectoryEntry和DN是我仅有的两条信息。我不能实例化新的DirectoryEntry,因为这样我就必须使用默认的目录和凭证,或者使用目录名/端口和用户名/密码。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-10 08:02:54

代码语言:javascript
复制
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();
    }
}
票数 5
EN

Stack Overflow用户

发布于 2011-04-07 05:30:33

您可以创建一个新的DirectoryEntry实例,提供DN as参数,然后尝试绑定(例如,通过刷新属性)。

DirectoryEntry e=新DirectoryEntry(dn,"u","p");

e.RefreshCache();

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5572776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档