开发者

LDAP with objectCategory query problem

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

deSearch.Filter = String.Format("(&(&(&(&(objectCateg开发者_开发知识库ory=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


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.


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜