我写了一个从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();
}
塔拉索夫
答案 0 :(得分: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();
}
答案 1 :(得分:0)
使用此过滤器
(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(l=yourcity))