Unable to get certain usernames from AD

Discussion in 'ASP .Net' started by furiousmojo@gmail.com, Jun 30, 2006.

  1. Guest

    The problem: Most usernames show up in the dropdownlist, but a random
    few do not show up. Why? If I put the filter below into my Users and
    Computers snap-in as an advanced search, it finds all of them.

    Here's the meat of the ldap search:

    Private Function GetUsernames() As DataTable

    Dim rootEntry As New DirectoryEntry("LDAP://" &
    ConfigurationManager.AppSettings("FQDN"))
    Dim searcher As New DirectorySearcher(rootEntry)
    searcher.SearchScope = SearchScope.Subtree

    searcher.Filter =
    "(&(ObjectClass=user)(ObjectCategory=person))"
    searcher.PropertiesToLoad.Add("samAccountName")

    Dim srcResults As SearchResultCollection = searcher.FindAll()

    Dim srResult As SearchResult
    Dim rpcPropertyCollection As ResultPropertyCollection
    Dim objMember As Object

    Dim myDataTable As New DataTable("dtUsers")

    Dim dcUserName As New DataColumn("UserName", GetType(String))

    myDataTable.Columns.Add(dcUserName)

    For Each srResult In srcResults
    Dim dr As DataRow
    dr = myDataTable.NewRow()
    dr("UserName") =
    CType(srResult.Properties("samAccountName")(0), String)
    myDataTable.Rows.Add(dr)
    Next

    myDataTable.DefaultView.Sort = "UserName"

    Return myDataTable
    End Function

    This is the binding of the datalist containing the column with
    dropdownlists of usernames.

    Private Sub BindSearchResultsDataList()

    Dim myDataListItem As DataListItem
    Dim strFirstName, strLastName As String

    strFirstName = txtFirstName.Text
    strLastName = txtLastName.Text

    strFirstName = Replace(strFirstName, "'", "''")
    strLastName = Replace(strLastName, "'", "''")

    Dim connectionString As String = DecryptConnectionString()
    Dim dbConnection As System.Data.IDbConnection = New
    System.Data.SqlClient.SqlConnection(connectionString)

    Dim queryString As String = "BLANKED OUT SELECT QUERY"
    Dim dbCommand As System.Data.IDbCommand = New
    System.Data.SqlClient.SqlCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection

    dbConnection.Open()

    Dim myReader As SqlDataReader
    myReader = dbCommand.ExecuteReader()

    dlSearchResults.DataSource = myReader
    dlSearchResults.DataBind()

    If dlSearchResults.Items.Count <> "0" Then
    dlSearchResults.Visible = True
    Else
    dlSearchResults.Visible = False
    lblSearchResult.Text = "No employees found."
    End If

    dbConnection.Close()

    Dim dtUsernames As DataTable = GetUsernames()

    For Each myDataListItem In dlSearchResults.Items
    CType(myDataListItem.FindControl("ddlUsername"),
    DropDownList).DataSource = dtUsernames
    CType(myDataListItem.FindControl("ddlUsername"),
    DropDownList).DataTextField = "Username"
    CType(myDataListItem.FindControl("ddlUsername"),
    DropDownList).DataValueField = "Username"
    CType(myDataListItem.FindControl("ddlUsername"),
    DropDownList).DataBind()
    CType(myDataListItem.FindControl("ddlUsername"),
    DropDownList).Items.Insert(0, "")
    Next
    End Sub


    ----------------------------------------------------------------------
     
    , Jun 30, 2006
    #1
    1. Advertising

  2. Guest

    Joe K. solved my problem! The answer was using searcher.pagesize. By
    default, the query is limited to 1000 results to prevent DOS attacks.

    wrote:
    > The problem: Most usernames show up in the dropdownlist, but a random
    > few do not show up. Why? If I put the filter below into my Users and
    > Computers snap-in as an advanced search, it finds all of them.
    >
    > Here's the meat of the ldap search:
    >
    > Private Function GetUsernames() As DataTable
    >
    > Dim rootEntry As New DirectoryEntry("LDAP://" &
    > ConfigurationManager.AppSettings("FQDN"))
    > Dim searcher As New DirectorySearcher(rootEntry)
    > searcher.SearchScope = SearchScope.Subtree
    >
    > searcher.Filter =
    > "(&(ObjectClass=user)(ObjectCategory=person))"
    > searcher.PropertiesToLoad.Add("samAccountName")
    >
    > Dim srcResults As SearchResultCollection = searcher.FindAll()
    >
    > Dim srResult As SearchResult
    > Dim rpcPropertyCollection As ResultPropertyCollection
    > Dim objMember As Object
    >
    > Dim myDataTable As New DataTable("dtUsers")
    >
    > Dim dcUserName As New DataColumn("UserName", GetType(String))
    >
    > myDataTable.Columns.Add(dcUserName)
    >
    > For Each srResult In srcResults
    > Dim dr As DataRow
    > dr = myDataTable.NewRow()
    > dr("UserName") =
    > CType(srResult.Properties("samAccountName")(0), String)
    > myDataTable.Rows.Add(dr)
    > Next
    >
    > myDataTable.DefaultView.Sort = "UserName"
    >
    > Return myDataTable
    > End Function
    >
    > This is the binding of the datalist containing the column with
    > dropdownlists of usernames.
    >
    > Private Sub BindSearchResultsDataList()
    >
    > Dim myDataListItem As DataListItem
    > Dim strFirstName, strLastName As String
    >
    > strFirstName = txtFirstName.Text
    > strLastName = txtLastName.Text
    >
    > strFirstName = Replace(strFirstName, "'", "''")
    > strLastName = Replace(strLastName, "'", "''")
    >
    > Dim connectionString As String = DecryptConnectionString()
    > Dim dbConnection As System.Data.IDbConnection = New
    > System.Data.SqlClient.SqlConnection(connectionString)
    >
    > Dim queryString As String = "BLANKED OUT SELECT QUERY"
    > Dim dbCommand As System.Data.IDbCommand = New
    > System.Data.SqlClient.SqlCommand
    > dbCommand.CommandText = queryString
    > dbCommand.Connection = dbConnection
    >
    > dbConnection.Open()
    >
    > Dim myReader As SqlDataReader
    > myReader = dbCommand.ExecuteReader()
    >
    > dlSearchResults.DataSource = myReader
    > dlSearchResults.DataBind()
    >
    > If dlSearchResults.Items.Count <> "0" Then
    > dlSearchResults.Visible = True
    > Else
    > dlSearchResults.Visible = False
    > lblSearchResult.Text = "No employees found."
    > End If
    >
    > dbConnection.Close()
    >
    > Dim dtUsernames As DataTable = GetUsernames()
    >
    > For Each myDataListItem In dlSearchResults.Items
    > CType(myDataListItem.FindControl("ddlUsername"),
    > DropDownList).DataSource = dtUsernames
    > CType(myDataListItem.FindControl("ddlUsername"),
    > DropDownList).DataTextField = "Username"
    > CType(myDataListItem.FindControl("ddlUsername"),
    > DropDownList).DataValueField = "Username"
    > CType(myDataListItem.FindControl("ddlUsername"),
    > DropDownList).DataBind()
    > CType(myDataListItem.FindControl("ddlUsername"),
    > DropDownList).Items.Insert(0, "")
    > Next
    > End Sub
    >
    >
    > ----------------------------------------------------------------------
     
    , Jul 7, 2006
    #2
    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?Sm9l?=

    IIS6 not logging Authenticated Usernames

    =?Utf-8?B?Sm9l?=, Sep 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    544
    Bruce Barker
    Sep 16, 2005
  2. Ahmed Moustafa
    Replies:
    5
    Views:
    456
    Brian Palmer
    Aug 20, 2003
  3. Replies:
    0
    Views:
    673
  4. Replies:
    2
    Views:
    545
    bruce barker
    Mar 25, 2008
  5. SAN CAZIANO
    Replies:
    8
    Views:
    193
    Dr John Stockton
    Oct 15, 2004
Loading...

Share This Page