【问题标题】:How I can find a User with the GUID(objectGUID) Parameter in Active Directory如何在 Active Directory 中找到具有 GUID(objectGUID) 参数的用户
【发布时间】:2012-07-23 13:43:34
【问题描述】:

在我的 ASP.NET 应用程序中,我从 Active Directory 获取信息。我必须使用 GUID 信息获取有关用户的信息(例如:a28a6a34dsfdsf57d9e54f945a241),但我不知道如何使用过滤器进行此搜索:/

例如,如果我搜索用户姓氏:

DirectoryEntry Entry = new DirectoryEntry("LDAP://" + "Domain");

            string filter = "(&(objectClass=user)(objectCategory=person)(cn=" + txtBenutzer.Text + "*))";

            DirectorySearcher Searcher = new DirectorySearcher(Entry, filter);

            var q = from s in Searcher.FindAll().OfType<SearchResult>()
                    select new
                    {
                        //GetProperty(s, "objectGUID"),
                        Benutzer = GetProperty(s, "sAMAccountName"),
                        eMail = GetProperty(s, "mail"),
                        Vorname = GetProperty(s, "givenName"),
                        Nachname = GetProperty(s, "sn"),
                        Telefon = GetProperty(s, "telephoneNumber"),
                        UserID = s.GetDirectoryEntry().NativeGuid

                    };

            this.myListView.DataSource = q;
            this.myListView.DataBind();

现在我需要一个带有 GUID 的过滤器,我可以在 AD 中找到唯一的用户。这个搜索的 GUID 我在一个字符串中 UserID = Session["UserID"].toString()

塔拉索夫

【问题讨论】:

    标签: c# asp.net active-directory ldap directoryentry


    【解决方案1】:

    你不需要搜索,如果你知道GUID,你可以直接绑定到对象,例如

    var user = new DirectoryEntry("LDAP://<GUID=119d0d80-699d-4e81-8e4e-5477e22ac1b3>");
    

    (替换为您的实际 ObjectGUID)。

    查看此 MSDN 条目:Using ObjectGUID to Bind to an Object

    【讨论】:

    • 哦,好的,我明天测试一下;)我给你一个请求
    • @Tarasov:很高兴它有帮助:) 如果它有效,您也可以接受答案。干杯。
    • 我的代码中有第二个错误,UserID = s.GetDirectoryEntry().NativeGuid 我必须使用 UserID = s.GetDirectoryEntry().Guid^^
    • 要接受答案,投票显示下方应该有一个标记。有关 NativeGuid 和 Guid 的区别,请参阅stackoverflow.com/questions/1644989/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多