listing Object properties from SearchResult

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default listing Object properties from SearchResult

    Hi
    I have the following lines of code that are suppose to list some selected
    properties of all the object entries in a SearchResult but the code is only
    listing one property ie. the 'sn' and the corresponding value for all the
    entries, do you have a clue why?
    TIA
    ----------------------
    foreach (SearchResult resEnt in resEntAll)
    {
    i++;
    dr = dt.NewRow();
    foreach (string propKy in resEnt.Properties.PropertyNames)
    {
    switch (propKy)
    {
    case "sn":
    y = 0;
    break;
    case "givenName":
    y = 1;
    break;
    case "telephoneNumber":
    y = 2;
    break;
    default:
    y = 3;
    break;
    }
    if (y < 3)
    {
    ResultPropertyValueCollection valco =
    resEnt.Properties[propKy];
    foreach (Object prop in valco)
    {
    dr[y] = prop.ToString();
    }
    }
    }
    dt.Rows.Add(dr);
    }

    --



    Guest

  2. Similar Questions and Discussions

    1. object properties
      I am using the trial version of Contribute CS3. When I edit a page and select a check-box or field, how can I inspect and change its properties? The...
    2. DirectorySearcher - SearchResult - User Groups
      Hi, I'm having trouble fetching the AD groups a user belongs to after authenticating them against Active Directory. My code is based on the How To...
    3. losing object properties when...
      i lose the capability to change an object's width and height in the properties tab after using the extrude tool on it. the properties tab then just...
    4. Accessing all properties of an object at Runtime
      Use reflection... "Softwaremaker" <msdn@removethis.softwaremaker.net> wrote in message news:<#b1mBjhQDHA.2432@TK2MSFTNGP10.phx.gbl>...
    5. Object properties in echo()
      I started using PHP's object-oriented stuff a little while ago, which has mostly been a joy. However, I've noticed that they don't seem to echo as I...
  3. #2

    Default Re: listing Object properties from SearchResult

    What did you put in to PropertiesToLoad? Also, it is possible that the
    security context you bound with only has rights to see a subset of the
    properties you requested.

    Those are my two best guesses given what you've told us.

    Joe K.

    <dl> wrote in message news:OCHzJf4VFHA.1148@tk2msftngp13.phx.gbl...
    > Hi
    > I have the following lines of code that are suppose to list some selected
    > properties of all the object entries in a SearchResult but the code is
    > only
    > listing one property ie. the 'sn' and the corresponding value for all the
    > entries, do you have a clue why?
    > TIA
    > ----------------------
    > foreach (SearchResult resEnt in resEntAll)
    > {
    > i++;
    > dr = dt.NewRow();
    > foreach (string propKy in resEnt.Properties.PropertyNames)
    > {
    > switch (propKy)
    > {
    > case "sn":
    > y = 0;
    > break;
    > case "givenName":
    > y = 1;
    > break;
    > case "telephoneNumber":
    > y = 2;
    > break;
    > default:
    > y = 3;
    > break;
    > }
    > if (y < 3)
    > {
    > ResultPropertyValueCollection valco =
    > resEnt.Properties[propKy];
    > foreach (Object prop in valco)
    > {
    > dr[y] = prop.ToString();
    > }
    > }
    > }
    > dt.Rows.Add(dr);
    > }
    >
    > --
    >
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default Re: listing Object properties from SearchResult

    I did tried to throw in the PropertiesToLoad lines; one for each property
    that I was going to get. But that didn't make any difference. Interesting
    enough the account I am using (to login via login.aspx) to list this
    directory is the same as the one I used to create the entries and the OU.
    Do I need to pass on the credential (somewhere) to this page ? or do I need
    to bind with the credential?
    TIA

    Here is my code before the foreach statements ..
    String strPath = "LDAP://ou=" + txtOUName.Text +
    ",dc=domain,dc=com";
    //Bind to the OU
    DirectoryEntry myEnt = new DirectoryEntry(strPath);

    //do a DirectorySearch
    DirectorySearcher mySearcher = new DirectorySearcher(myEnt);
    mySearcher.PropertiesToLoad.Add("sn");
    mySearcher.PropertiesToLoad.Add("givenName");
    mySearcher.PropertiesToLoad.Add("telephoneNumber") ;

    mySearcher.Filter = "(objectClass=user)";

    SearchResultCollection resEntAll = mySearcher.FindAll();


    "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    in message news:uynwLa8VFHA.2692@TK2MSFTNGP15.phx.gbl...
    > What did you put in to PropertiesToLoad? Also, it is possible that the
    > security context you bound with only has rights to see a subset of the
    > properties you requested.
    >
    > Those are my two best guesses given what you've told us.
    >
    > Joe K.
    >
    > <dl> wrote in message news:OCHzJf4VFHA.1148@tk2msftngp13.phx.gbl...
    > > Hi
    > > I have the following lines of code that are suppose to list some
    selected
    > > properties of all the object entries in a SearchResult but the code is
    > > only
    > > listing one property ie. the 'sn' and the corresponding value for all
    the
    > > entries, do you have a clue why?
    > > TIA
    > > ----------------------
    > > foreach (SearchResult resEnt in resEntAll)
    > > {
    > > i++;
    > > dr = dt.NewRow();
    > > foreach (string propKy in
    resEnt.Properties.PropertyNames)
    > > {
    > > switch (propKy)
    > > {
    > > case "sn":
    > > y = 0;
    > > break;
    > > case "givenName":
    > > y = 1;
    > > break;
    > > case "telephoneNumber":
    > > y = 2;
    > > break;
    > > default:
    > > y = 3;
    > > break;
    > > }
    > > if (y < 3)
    > > {
    > > ResultPropertyValueCollection valco =
    > > resEnt.Properties[propKy];
    > > foreach (Object prop in valco)
    > > {
    > > dr[y] = prop.ToString();
    > > }
    > > }
    > > }
    > > dt.Rows.Add(dr);
    > > }
    > >
    > > --
    > >
    > >
    > >
    >
    >

    Guest

  5. #4

    Default Re: listing Object properties from SearchResult

    The directoryentry used for the searchroot object determines the security
    context that the search is performed with. It is possible that you are
    authenticating anonymously, and thus can't see many properties. You can
    verify this by passing in credentials to the DirectoryEntry before executing
    the search and seeing if you get different results. If so, that was the
    problem.

    If that is the problem, there are other ways to solve it than using a
    hard-coded service account, but it is the easiest way to verify the issue.

    Joe K.

    <dl> wrote in message news:%23kJpCn8VFHA.2768@tk2msftngp13.phx.gbl...
    >I did tried to throw in the PropertiesToLoad lines; one for each property
    > that I was going to get. But that didn't make any difference.
    > Interesting
    > enough the account I am using (to login via login.aspx) to list this
    > directory is the same as the one I used to create the entries and the OU.
    > Do I need to pass on the credential (somewhere) to this page ? or do I
    > need
    > to bind with the credential?
    > TIA
    >
    > Here is my code before the foreach statements ..
    > String strPath = "LDAP://ou=" + txtOUName.Text +
    > ",dc=domain,dc=com";
    > //Bind to the OU
    > DirectoryEntry myEnt = new DirectoryEntry(strPath);
    >
    > //do a DirectorySearch
    > DirectorySearcher mySearcher = new DirectorySearcher(myEnt);
    > mySearcher.PropertiesToLoad.Add("sn");
    > mySearcher.PropertiesToLoad.Add("givenName");
    > mySearcher.PropertiesToLoad.Add("telephoneNumber") ;
    >
    > mySearcher.Filter = "(objectClass=user)";
    >
    > SearchResultCollection resEntAll = mySearcher.FindAll();
    >
    >
    > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    > in message news:uynwLa8VFHA.2692@TK2MSFTNGP15.phx.gbl...
    >> What did you put in to PropertiesToLoad? Also, it is possible that the
    >> security context you bound with only has rights to see a subset of the
    >> properties you requested.
    >>
    >> Those are my two best guesses given what you've told us.
    >>
    >> Joe K.
    >>
    >> <dl> wrote in message news:OCHzJf4VFHA.1148@tk2msftngp13.phx.gbl...
    >> > Hi
    >> > I have the following lines of code that are suppose to list some
    > selected
    >> > properties of all the object entries in a SearchResult but the code is
    >> > only
    >> > listing one property ie. the 'sn' and the corresponding value for all
    > the
    >> > entries, do you have a clue why?
    >> > TIA
    >> > ----------------------
    >> > foreach (SearchResult resEnt in resEntAll)
    >> > {
    >> > i++;
    >> > dr = dt.NewRow();
    >> > foreach (string propKy in
    > resEnt.Properties.PropertyNames)
    >> > {
    >> > switch (propKy)
    >> > {
    >> > case "sn":
    >> > y = 0;
    >> > break;
    >> > case "givenName":
    >> > y = 1;
    >> > break;
    >> > case "telephoneNumber":
    >> > y = 2;
    >> > break;
    >> > default:
    >> > y = 3;
    >> > break;
    >> > }
    >> > if (y < 3)
    >> > {
    >> > ResultPropertyValueCollection valco =
    >> > resEnt.Properties[propKy];
    >> > foreach (Object prop in valco)
    >> > {
    >> > dr[y] = prop.ToString();
    >> > }
    >> > }
    >> > }
    >> > dt.Rows.Add(dr);
    >> > }
    >> >
    >> > --
    >> >
    >> >
    >> >
    >>
    >>
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

  6. #5

    Default Re: listing Object properties from SearchResult

    Hi Joe
    I just tried passing in the credentials with DirectoryEntry(strpath, uName,
    pwd, AuthenticationTypes.Secure) but it is still giving me the last name
    only!

    I guess I might have to revisit my whole dev setup for forms authentication.
    Is there a place / book I can look into about forms authentication with AD
    in ASP.NET? I thing I need to workout a checklist in each area.

    TIA


    "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    in message news:e4ejkT9VFHA.3216@TK2MSFTNGP10.phx.gbl...
    > The directoryentry used for the searchroot object determines the security
    > context that the search is performed with. It is possible that you are
    > authenticating anonymously, and thus can't see many properties. You can
    > verify this by passing in credentials to the DirectoryEntry before
    executing
    > the search and seeing if you get different results. If so, that was the
    > problem.
    >
    > If that is the problem, there are other ways to solve it than using a
    > hard-coded service account, but it is the easiest way to verify the issue.
    >
    > Joe K.
    >
    > <dl> wrote in message news:%23kJpCn8VFHA.2768@tk2msftngp13.phx.gbl...
    > >I did tried to throw in the PropertiesToLoad lines; one for each property
    > > that I was going to get. But that didn't make any difference.
    > > Interesting
    > > enough the account I am using (to login via login.aspx) to list this
    > > directory is the same as the one I used to create the entries and the
    OU.
    > > Do I need to pass on the credential (somewhere) to this page ? or do I
    > > need
    > > to bind with the credential?
    > > TIA
    > >
    > > Here is my code before the foreach statements ..
    > > String strPath = "LDAP://ou=" + txtOUName.Text +
    > > ",dc=domain,dc=com";
    > > //Bind to the OU
    > > DirectoryEntry myEnt = new DirectoryEntry(strPath);
    > >
    > > //do a DirectorySearch
    > > DirectorySearcher mySearcher = new DirectorySearcher(myEnt);
    > > mySearcher.PropertiesToLoad.Add("sn");
    > > mySearcher.PropertiesToLoad.Add("givenName");
    > > mySearcher.PropertiesToLoad.Add("telephoneNumber") ;
    > >
    > > mySearcher.Filter = "(objectClass=user)";
    > >
    > > SearchResultCollection resEntAll = mySearcher.FindAll();
    > >
    > >
    > > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
    wrote
    > > in message news:uynwLa8VFHA.2692@TK2MSFTNGP15.phx.gbl...
    > >> What did you put in to PropertiesToLoad? Also, it is possible that the
    > >> security context you bound with only has rights to see a subset of the
    > >> properties you requested.
    > >>
    > >> Those are my two best guesses given what you've told us.
    > >>
    > >> Joe K.
    > >>
    > >> <dl> wrote in message news:OCHzJf4VFHA.1148@tk2msftngp13.phx.gbl...
    > >> > Hi
    > >> > I have the following lines of code that are suppose to list some
    > > selected
    > >> > properties of all the object entries in a SearchResult but the code
    is
    > >> > only
    > >> > listing one property ie. the 'sn' and the corresponding value for all
    > > the
    > >> > entries, do you have a clue why?
    > >> > TIA
    > >> > ----------------------
    > >> > foreach (SearchResult resEnt in resEntAll)
    > >> > {
    > >> > i++;
    > >> > dr = dt.NewRow();
    > >> > foreach (string propKy in
    > > resEnt.Properties.PropertyNames)
    > >> > {
    > >> > switch (propKy)
    > >> > {
    > >> > case "sn":
    > >> > y = 0;
    > >> > break;
    > >> > case "givenName":
    > >> > y = 1;
    > >> > break;
    > >> > case "telephoneNumber":
    > >> > y = 2;
    > >> > break;
    > >> > default:
    > >> > y = 3;
    > >> > break;
    > >> > }
    > >> > if (y < 3)
    > >> > {
    > >> > ResultPropertyValueCollection valco =
    > >> > resEnt.Properties[propKy];
    > >> > foreach (Object prop in valco)
    > >> > {
    > >> > dr[y] = prop.ToString();
    > >> > }
    > >> > }
    > >> > }
    > >> > dt.Rows.Add(dr);
    > >> > }
    > >> >
    > >> > --
    > >> >
    > >> >
    > >> >
    > >>
    > >>
    > >
    > >
    >
    >

    Guest

  7. #6

    Default Re: listing Object properties from SearchResult

    I'm not sure of any good articles or books (yet). MS has an article for
    forms auth with AD that I rarely recommend to people because I think it is
    pretty flawed, but you can look at it.

    [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;326340[/url]

    The next thing I'd try is using a utility to ldp.exe to try your searches
    there and see if you get similar results. Sometimes it is helpful to get
    the extra layers out of the way and test things in a UI.

    You might also try the contains method to verify whether the
    SearchResult.Properties has the attributes you want.

    Joe K.

    <dl> wrote in message news:Oo0qa6BWFHA.2128@TK2MSFTNGP15.phx.gbl...
    > Hi Joe
    > I just tried passing in the credentials with DirectoryEntry(strpath,
    > uName,
    > pwd, AuthenticationTypes.Secure) but it is still giving me the last name
    > only!
    >
    > I guess I might have to revisit my whole dev setup for forms
    > authentication.
    > Is there a place / book I can look into about forms authentication with AD
    > in ASP.NET? I thing I need to workout a checklist in each area.
    >
    > TIA
    >
    >
    > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    > in message news:e4ejkT9VFHA.3216@TK2MSFTNGP10.phx.gbl...
    >> The directoryentry used for the searchroot object determines the security
    >> context that the search is performed with. It is possible that you are
    >> authenticating anonymously, and thus can't see many properties. You can
    >> verify this by passing in credentials to the DirectoryEntry before
    > executing
    >> the search and seeing if you get different results. If so, that was the
    >> problem.
    >>
    >> If that is the problem, there are other ways to solve it than using a
    >> hard-coded service account, but it is the easiest way to verify the
    >> issue.
    >>
    >> Joe K.
    >>
    >> <dl> wrote in message news:%23kJpCn8VFHA.2768@tk2msftngp13.phx.gbl...
    >> >I did tried to throw in the PropertiesToLoad lines; one for each
    >> >property
    >> > that I was going to get. But that didn't make any difference.
    >> > Interesting
    >> > enough the account I am using (to login via login.aspx) to list this
    >> > directory is the same as the one I used to create the entries and the
    > OU.
    >> > Do I need to pass on the credential (somewhere) to this page ? or do I
    >> > need
    >> > to bind with the credential?
    >> > TIA
    >> >
    >> > Here is my code before the foreach statements ..
    >> > String strPath = "LDAP://ou=" + txtOUName.Text +
    >> > ",dc=domain,dc=com";
    >> > //Bind to the OU
    >> > DirectoryEntry myEnt = new DirectoryEntry(strPath);
    >> >
    >> > //do a DirectorySearch
    >> > DirectorySearcher mySearcher = new DirectorySearcher(myEnt);
    >> > mySearcher.PropertiesToLoad.Add("sn");
    >> > mySearcher.PropertiesToLoad.Add("givenName");
    >> > mySearcher.PropertiesToLoad.Add("telephoneNumber") ;
    >> >
    >> > mySearcher.Filter = "(objectClass=user)";
    >> >
    >> > SearchResultCollection resEntAll = mySearcher.FindAll();
    >> >
    >> >
    >> > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
    > wrote
    >> > in message news:uynwLa8VFHA.2692@TK2MSFTNGP15.phx.gbl...
    >> >> What did you put in to PropertiesToLoad? Also, it is possible that
    >> >> the
    >> >> security context you bound with only has rights to see a subset of the
    >> >> properties you requested.
    >> >>
    >> >> Those are my two best guesses given what you've told us.
    >> >>
    >> >> Joe K.
    >> >>
    >> >> <dl> wrote in message news:OCHzJf4VFHA.1148@tk2msftngp13.phx.gbl...
    >> >> > Hi
    >> >> > I have the following lines of code that are suppose to list some
    >> > selected
    >> >> > properties of all the object entries in a SearchResult but the code
    > is
    >> >> > only
    >> >> > listing one property ie. the 'sn' and the corresponding value for
    >> >> > all
    >> > the
    >> >> > entries, do you have a clue why?
    >> >> > TIA
    >> >> > ----------------------
    >> >> > foreach (SearchResult resEnt in resEntAll)
    >> >> > {
    >> >> > i++;
    >> >> > dr = dt.NewRow();
    >> >> > foreach (string propKy in
    >> > resEnt.Properties.PropertyNames)
    >> >> > {
    >> >> > switch (propKy)
    >> >> > {
    >> >> > case "sn":
    >> >> > y = 0;
    >> >> > break;
    >> >> > case "givenName":
    >> >> > y = 1;
    >> >> > break;
    >> >> > case "telephoneNumber":
    >> >> > y = 2;
    >> >> > break;
    >> >> > default:
    >> >> > y = 3;
    >> >> > break;
    >> >> > }
    >> >> > if (y < 3)
    >> >> > {
    >> >> > ResultPropertyValueCollection valco =
    >> >> > resEnt.Properties[propKy];
    >> >> > foreach (Object prop in valco)
    >> >> > {
    >> >> > dr[y] = prop.ToString();
    >> >> > }
    >> >> > }
    >> >> > }
    >> >> > dt.Rows.Add(dr);
    >> >> > }
    >> >> >
    >> >> > --
    >> >> >
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >
    >>
    >>
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139