0

Active Directory からデータを取得するプログラムを作成しました。データを l (都市) パラメーターにフィルター処理する LDAP フィルターが必要です。

私のコード:

public void SearchByCity(string city)
        {
                                                         //What I must do :(
            DirectoryEntry Entry = new DirectoryEntry("LDAP://<l= + city + >");
            string filter = "(&(objectClass=user)(objectCategory=person)(cn=*))";
            DirectorySearcher Searcher = new DirectorySearcher(Entry, filter);

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

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

タラソフ

4

2 に答える 2

0

このフィルターを使用

(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(l=yourcity))
于 2013-08-12T11:48:47.800 に答える
0

ソリューション:

public void SearchByPlace(string city)
        {
            DirectoryEntry Entry = new DirectoryEntry("LDAP://" + Properties.Settings.Default.Domain);
            string filter = "(&(objectClass=user)(objectCategory=person)(l=" + city + ")(cn=*))";
            DirectorySearcher Searcher = new DirectorySearcher(Entry, filter);

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

            this.myListView.DataSource = q;
            this.myListView.DataBind();
        }
于 2012-07-25T06:07:29.043 に答える