LDAP 与 objectCategory 查询问题

发布于 2024-10-17 17:11:16 字数 360 浏览 1 评论 0原文

我想创建 LDAP 查询来按名称、位置和型号过滤打印机

deSearch.Filter = String.Format("(&(&(&(&(objectCategory=printQueue)(printername={0}))(location={1}))(driverName={2})))", queueName, location, modelNumber);

我创建了此查询,但它运行不正确

  1. 第一个问题是如果其中一个条件为空或 null,则按所有搜索条件一起搜索
  2. ,我将其设置为 *得到所有结果。它正确吗?

欢迎所有想法

I want to create LDAP query to filter printers by name and location and model

deSearch.Filter = String.Format("(&(&(&(&(objectCategory=printQueue)(printername={0}))(location={1}))(driverName={2})))", queueName, location, modelNumber);

I create this but it didn't run correctly

  1. The first problem is to search by all search criteria together
  2. if one of criteria is empty or null ,I set it by * to get all results .Is it correct ?

All ideas are welcomed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫负雪 2024-10-24 17:11:16

您只需要一个 &操作员。它们是 LDAP 过滤器表达式中的 n 元运算符,而不是二进制运算符:

(&(objectCategory=printQueue)(printername={0})(location={1})(driverName={2}))

(RFC 2254 将 &(或 |)后面的内容定义为一组过滤器,而不是恰好两个过滤器。这是我能看到的唯一好的理由为什么他们选择那个可怕的前缀符号。)

我个人也会在这样的查询中提供“printQueue”作为参数。

'*' 将匹配任何属性值,但它要求该属性实际存在,即 objectClass具有这样的属性。

You only need one & operator. They are n-ary, not binary, operators in LDAP filter expressions:

(&(objectCategory=printQueue)(printername={0})(location={1})(driverName={2}))

(RFC 2254 defines what follows the & (or |) as a SET OF Filter, not as exactly two filters. This is about the only good reason I can see why they chose that ghastly prefix notation.)

I would personally supply 'printQueue' as an argument as well in a query like this.

'*' will match any attribute value, but it requires the attribute to be actually present, i.e. for the objectClass to have such an attribute.

じ违心 2024-10-24 17:11:16

根据 EJP 回复,我在这里创建了代码

 StringBuilder filter=new StringBuilder("(&(objectClass=printQueue)");
        if (!string.IsNullOrEmpty(queueName))
            filter.Append("(printerName=*"+queueName+"*)") ;

        if (!string.IsNullOrEmpty(location))

            filter.Append("(location=*" + location + "*)");

        if (!string.IsNullOrEmpty(modelNumber))

            filter.Append("(driverName=*" + modelNumber + "*)");

        filter.Append(")");

        deSearch.Filter = filter.ToString();

Accoroding to EJP reply I created the code for that here

 StringBuilder filter=new StringBuilder("(&(objectClass=printQueue)");
        if (!string.IsNullOrEmpty(queueName))
            filter.Append("(printerName=*"+queueName+"*)") ;

        if (!string.IsNullOrEmpty(location))

            filter.Append("(location=*" + location + "*)");

        if (!string.IsNullOrEmpty(modelNumber))

            filter.Append("(driverName=*" + modelNumber + "*)");

        filter.Append(")");

        deSearch.Filter = filter.ToString();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文