我有一个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();
}
}
关于c# - 如何从 DirectoryEntry 和 DN 检索 DirectoryEntry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5572776/