简体   繁体   English

使用 C# 在 LDAP 中搜索标题?

[英]Search for a title in LDAP using C#?

I'm trying to search for a user's title in LDAP using C#.我正在尝试使用 C# 在 LDAP 中搜索用户的职位。

My current search is this, in which I'm trying to search for a Janitor named John Smith:我目前的搜索是这样的,我试图在其中搜索名为 John Smith 的清洁工:

search.Filter = "(&(objectCategory=person)(objectClass=contact)(|(sn=Smith)(givenname=John)(title=Janitor)))";

It's not working though.虽然它不起作用。

Can anyone point me to where I'm going wrong?谁能指出我哪里出错了? I know I've got the sn and givenname portion correct as that part works .. .我知道我的sngivenname部分是正确的,因为该部分有效...... but the title filter isn't .但标题过滤器不是。

That's probably because that Title attribute is really called personalTitle in LDAP.这可能是因为Title属性在 LDAP 中实际上称为personalTitle

Try this search filter instead:试试这个搜索过滤器:

search.Filter = "(&(objectCategory=person)(objectClass=contact)(|(sn=Smith)(givenname=John)(personalTitle=Janitor)))";

Active Directory MVP Richard Mueller has a great site with invaluable information on how to use AD from .NET - find his references documents (Excel sheets) here - download them, use them - enjoy! Active Directory MVP Richard Mueller 有一个很棒的站点,其中包含有关如何从 .NET 使用 AD 的宝贵信息——在此处找到他的参考文档(Excel 表格) ——下载它们,使用它们——享受吧!

What LDAP server are you using ?您使用的是什么 LDAP 服务器?

On CentOs DS, this one works :在 CentOs DS 上,这个有效:

search.Filter = "(&(objectClass=person)(sn=Smith)(givenname=John)(title=Janitor))";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM