listing Object properties from SearchResult

Discussion in 'ASP .Net Security' started by Guest, May 13, 2005.

  1. Guest

    Guest Guest

    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, May 13, 2005
    #1
    1. Advertising

  2. 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:...
    > 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\), May 13, 2005
    #2
    1. Advertising

  3. Guest

    Guest Guest

    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)" <> wrote
    in message news:...
    > 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:...
    > > 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, May 13, 2005
    #3
  4. 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:%...
    >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)" <> wrote
    > in message news:...
    >> 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:...
    >> > 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\), May 13, 2005
    #4
  5. Guest

    Guest Guest

    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)" <> wrote
    in message news:...
    > 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:%...
    > >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)" <>

    wrote
    > > in message news:...
    > >> 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:...
    > >> > 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, May 14, 2005
    #5
  6. 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.

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

    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:...
    > 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)" <> wrote
    > in message news:...
    >> 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:%...
    >> >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)" <>

    > wrote
    >> > in message news:...
    >> >> 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:...
    >> >> > 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\), May 14, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWc=?=
    Replies:
    0
    Views:
    462
    =?Utf-8?B?bWc=?=
    Feb 7, 2004
  2. =?Utf-8?B?bWc=?=
    Replies:
    0
    Views:
    602
    =?Utf-8?B?bWc=?=
    Feb 8, 2004
  3. John

    Listing properties of an object

    John, May 3, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    293
    AlexS
    May 7, 2007
  4. George Durzi

    DirectorySearcher - SearchResult - User Groups

    George Durzi, Dec 16, 2004, in forum: ASP .Net Security
    Replies:
    4
    Views:
    318
    George Durzi
    Dec 17, 2004
  5. Une bévue

    listing object properties and/or method

    Une bévue, Sep 30, 2006, in forum: Javascript
    Replies:
    6
    Views:
    82
    Une bévue
    Sep 30, 2006
Loading...

Share This Page