我有一个表示用户的DirectoryEntry对象。从DirectoryEntry.Properties集合中,我将检索"manager"属性,该属性将为我提供用户经理的可分辨名称("DN")值。
我可以仅从这两个对象中检索管理器的DirectoryEntry对象吗?如果是这样的话,是怎么做的?
我正在设想类似于DirectoryEntry.GetEntryFromDN(dnManager);的东西,但我找不到类似的调用。
为了澄清,DirectoryEntry和DN是我仅有的两条信息。我不能实例化新的DirectoryEntry,因为这样我就必须使用默认的目录和凭证,或者使用目录名/端口和用户名/密码。
发布于 2011-04-10 08:02:54
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();
}
}发布于 2011-04-07 05:30:33
您可以创建一个新的DirectoryEntry实例,提供DN as参数,然后尝试绑定(例如,通过刷新属性)。
DirectoryEntry e=新DirectoryEntry(dn,"u","p");
e.RefreshCache();
https://stackoverflow.com/questions/5572776
复制相似问题