Ravikiran
Ravikiran

Reputation: 21

LDAP OR condition - Invalid filter

I have developed a small application which reads user information from Active directory. In the beginning of the application I used the below filter

search.Filter = "(&((&(objectCategory=Person)(objectClass=User)))(displayName=*" + username + "*))";

This worked fine.

Now, I am giving the user an option to retrieve the employee details based on username OR office OR title fields.

The query I used to get the details is as follows, but not working. It throws and exception

"search filter is invalid."

(&((&(objectCategory=Person)(objectClass=User)))(|((displayName=*" + username + "*)(l = *" + location + "*)(title=*" + title + "*))))";

Example: retieve the details of employee based on location : Hyderabad The runtime query looks like this

(&((&(objectCategory=Person)(objectClass=User)))(|((displayName=**)(l = *hyder*)(title=**)))

search filter is invalid.

Upvotes: 1

Views: 944

Answers (1)

jwilleke
jwilleke

Reputation: 10976

I think, as your intentions are not clear, what you are looking for is something more like:

(&(objectCategory=Person)(objectClass=User)(|(displayName=sam)(l=location)(title=title)))

Which could be visualized as:
(&
    (objectCategory=Person)
    (objectClass=User)
    (|
        (displayName=*sam*)
        (l=*location*)
        (title=*title*)
    )
)

Of course you would need to put in your code parameters instead of the values shown.

Upvotes: 1

Related Questions