检索 Active Directory DirectoryEntry 的街道地址属性

发布于 2024-12-12 06:55:57 字数 567 浏览 0 评论 0原文

我有一个 Active Directory 用户 DirectoryEntries 的集合,我需要获取与每个目录关联的街道地址。我正在使用以下内容:

    bool TryGetPropertyValue(DirectoryEntry de, string propertyName, out string propertyValue)
    {
        if (de.Properties.Contains(propertyName) && de.Properties[propertyName].Count > 0)
        {
            propertyValue = de.Properties[propertyName][0].ToString();
            return true;
        }
        propertyValue = string.Empty;
        return false;
    }

但是我找不到可以获取用户地址的 propertyName 值。是否存在,或者是否有另一种方式来获取此信息?

I have a collection of Active Directory user DirectoryEntries and I need to get the street address associated with each. I'm using something along the lines of:

    bool TryGetPropertyValue(DirectoryEntry de, string propertyName, out string propertyValue)
    {
        if (de.Properties.Contains(propertyName) && de.Properties[propertyName].Count > 0)
        {
            propertyValue = de.Properties[propertyName][0].ToString();
            return true;
        }
        propertyValue = string.Empty;
        return false;
    }

But I can't find a value of propertyName that will get the address of the user. Does one exist, or is there another way to get this information?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2024-12-19 06:55:57

请注意获取 DirectoryEntry de 的方式。从纯粹的 LDAP 角度来看,最好在目录搜索期间指定您真正想要检索的属性。我知道大多数开发人员都认为所有属性都应该是可检索的,但从 LDAP 的角度来看,情况并不那么明显:

/* Connection to Active Directory
 */
string sFromWhere = "LDAP://WM2008R2ENT:389/dc=dom,dc=fr";
DirectoryEntry deBase = new DirectoryEntry(sFromWhere, "dom\\jpb", "root.123");

DirectorySearcher dsLookFor = new DirectorySearcher(deBase);
dsLookFor.Filter = "(CN=user1 Users)";
dsLookFor.SearchScope = SearchScope.Subtree;
dsLookFor.PropertiesToLoad.Add("cn");
// Add one line for each property you need.
dsLookFor.PropertiesToLoad.Add("...");


SearchResultCollection srcUsers = dsLookFor.FindAll();

从属性名称的角度来看,您最好参考 Active Directory 架构和专业所有属性

为了将属性与用户和计算机 Active-Directory MMC 中的输入字段链接起来,您可以使用 LDP.EXE(W2K8 中固有的,来自 W2K3 中的资源工具包)。另一个有趣的工具是 Apache Directory Studio。它适用于所有平台(Linux (MAC)、Microsoft),并允许您浏览目录和架构。

Be careful of the way you get DirectoryEntry de. On pure LDAP point of view, it's better to specify during a directory search the attributes that you really want to retreive. I know that most of developpers suppose that all attributes should be retreive, but on the LDAP point of view it's not so evident :

/* Connection to Active Directory
 */
string sFromWhere = "LDAP://WM2008R2ENT:389/dc=dom,dc=fr";
DirectoryEntry deBase = new DirectoryEntry(sFromWhere, "dom\\jpb", "root.123");

DirectorySearcher dsLookFor = new DirectorySearcher(deBase);
dsLookFor.Filter = "(CN=user1 Users)";
dsLookFor.SearchScope = SearchScope.Subtree;
dsLookFor.PropertiesToLoad.Add("cn");
// Add one line for each property you need.
dsLookFor.PropertiesToLoad.Add("...");


SearchResultCollection srcUsers = dsLookFor.FindAll();

On the attributes names point of view you'd better refer to Active Directory Schema and specialy All atributes.

In order to link an attribute with an entry field in the user and computer Active-Directory MMC you can use LDP.EXE (which is native in W2K8, and come from the ressource kit in W2K3). Another interesting tool is Apache Directory Studio. It works on all plateforms (Linux (MAC), Microsoft) and allow you to browse the Directory and the Schema.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文