?
Solved

Active Directory filter syntax....

Posted on 2007-03-26
11
Medium Priority
?
4,094 Views
Last Modified: 2011-09-20
Hi,
I need to get all the objectClass which are = user
and the OU match a variant i compare to.
I wrote:
search.Filter = "(&(objectClass=user)(OU=_VAR))";
but the search result get nothing. (_VAR is a variant in which i pass a string).
What is the right syntax??
Thanks
0
Comment
Question by:udir
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 18792165
try this instead


search.Filter = "(&(objectClass=user)(OU=" & _VAR & "))";

Scott
0
 
LVL 1

Author Comment

by:udir
ID: 18792244
Hi,
Thanks for the reply.
I forgot to mention - C#,
OK, i wrote -
search.Filter = "(&(objectClass=user)(OU=" + _VAR+ "))";
but i get nothing.
If i put the filter in the LDAP it's OK  -
      DirectoryEntry root = new DirectoryEntry("LDAP://10.1.1.1/OU=" + _VAR + ",DC=Internet,DC=Ladpc",
             "User", "Pass", AuthenticationTypes.ServerBind);

            DirectorySearcher search = new DirectorySearcher(root);
            search.Filter = "(&(objectClass=user))";

Any Idea?
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 18792578
Im not sure you can filter on ou the way you are trying to...

but as you said if you add the ou in to the adspath then its working so you can just use that

Scott
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:udir
ID: 18792640
My problem is that i need to move the LDAP path to the app.config.
i wrote (at the app.config) :
<activeDirectorySettings defaultServer="Test">
    <servers>
      <clear />
      <add host="10.1.1.1" namingContext="DC=Internet,DC=Ladpc" userName="User" password="Password" name="Test" AuthenticationTypes="ServerBind" />
        </servers>
  </activeDirectorySettings>

And my problem is that i don't know how to pass a variant (_VAR) to the app.config.
If i will succeed doing it in this way, it will solve my problem!!
Can you help with that?   (I mean - pass a variant to app.config - if it is possible)
Thanks
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 18792731
so what does your code snippet look like when it is using the app.config file?

Scott
0
 
LVL 8

Expert Comment

by:Rytmis
ID: 18792741
search.Filter = String.Format("(&(objectClass=user)(dn=*OU={0}*))", _VAR);

This should work, since the OU should be a part of the DN of the object. Remember to set the search scope to Subtree.
0
 
LVL 1

Author Comment

by:udir
ID: 18792861
Rytmis, sorry i steel get nothing.
Colosseo - it looks like that -
        public static string ADconnectionString = ConfigurationManager.AppSettings["Test"];
        DirectoryEntry root = new DirectoryEntry(DataComm.ADconnectionString);
       
 
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 18792981
Rytmis could be on to the solution you need

try adspath instead of dn:

search.Filter = String.Format("(&(objectClass=user)(adspath=*OU={0}*))", _VAR);
0
 
LVL 1

Author Comment

by:udir
ID: 18793161
Sorry guys it just dosn't retrieve anything, (  Thanks for the effort  (:    )
my code is :
--------------------------------------------------------------
            public static string ADconnectionString = ConfigurationManager.AppSettings["Test"];
            DirectoryEntry root = new DirectoryEntry(DataComm.ADconnectionString);
            DirectorySearcher search = new DirectorySearcher(root);
            search.SearchScope = SearchScope.Subtree;
            search.Filter = String.Format("(&(objectClass=user)(ADsPath=*OU={0}*))", _VAR);

            search.PropertiesToLoad.Add("Name");
            search.PropertiesToLoad.Add("ID");

            SearchResult result;
            SearchResultCollection resultCol = search.FindAll();
           
           string[] allUsers = new string[resultCol.Count];
            string[] allID = new string[resultCol.Count];

            if (resultCol != null)
            {
                for(int counter=0; counter < resultCol.Count; counter++)
------------------------------------------------------------------------------------- and so on....
Count allways  = 0 !! , but again, if i put the " OU=_VAR " at the LDAP it's OK.
What else can i do???
0
 
LVL 8

Accepted Solution

by:
Rytmis earned 2000 total points
ID: 18793359
The other option is to put the placeholder in your namingContext attribute in the app configuration:
<add host="10.1.1.1" namingContext="OU={0},DC=Internet,DC=Ladpc" userName="User" password="Password" name="Test" AuthenticationTypes="ServerBind" />

and then:

string adConnectionString = String.Format(ConfigurationManager.AppSettings["Test"], _VAR);

(I'm assuming that AppSettings["Test"] returns the connection string as a concatenated string composed from attributes of the app.config element)

This is not the prettiest solution, but it should work. :)

0
 
LVL 1

Author Comment

by:udir
ID: 18794576
Great thanks it works!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question