8

在我的 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()

塔拉索夫

4

1 回答 1

22

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

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

(替换为您的实际 ObjectGUID)。

检查此 MSDN 条目:使用 ObjectGUID 绑定到对象

于 2012-07-23T14:28:08.943 回答