locked
Users are receiving other people information RRS feed

  • Question

  • User1241303409 posted

    Hi,

     I'm having a problem with a Intranet application i have developed. What it does, is it grabs the user's logon name, queries active directory using this and returns the results in a datatable then the main page displays this information.

    The problem i am having is, some people are receiving other peoples information instead, it is not recognising the correct person. Im wondering if there is some conflict of some kind happening

    The code uses this function to get the username:

        Private Function GetUsername() As String

            Return My.User.Name.ToUpper.Replace("RAYMARINE\", "").ToString

        End Function

     Private Function GetUsername() As String
            Return My.User.Name.ToUpper.Replace("RAYMARINE\", "").ToString
        End Function


    And this code to return a datatable of information about the user

     Private Function GetUserInfoFromADDT(ByVal logon As String, ByVal managerName As String) As DataTable


            Dim dt As New DataTable("contacts")

            With dt

                .Columns.Add("displayname")

                .Columns.Add("telephoneNumber")

                .Columns.Add("manager")

                .Columns.Add("department")

                .Columns.Add("location")

                .Columns.Add("title")

                .Columns.Add("mail")

            End With




            Dim DirSearcher As DirectorySearcher

            Dim DirSearchResultCol As SearchResultCollection

            'Set up the connection and search to AD


            Using dirEntry As New DirectoryEntry(ConfigurationManager.ConnectionStrings("ADConn").ConnectionString)

                DirSearcher = New DirectorySearcher(dirEntry)

                With DirSearcher

                    If managerName <> "" Then

                        .Filter = "(&(objectCategory=person)(objectClass=user)(displayName=" & managerName & "))"

                    Else

                        .Filter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & logon & "))"

                    End If

                    .PropertiesToLoad.Add("displayname")

                    .PropertiesToLoad.Add("telephoneNumber")

                    .PropertiesToLoad.Add("manager")

                    .PropertiesToLoad.Add("department")

                    .PropertiesToLoad.Add("physicalDeliveryOfficeName")

                    .PropertiesToLoad.Add("title")

                    .PropertiesToLoad.Add("mail")

                    DirSearchResultCol = .FindAll 'Added to collection

                    DirSearcher.Dispose()

                End With

            End Using



            Dim objResult As SearchResult

            Dim strName As String = ""

            Dim strExt As String = ""

            Dim strManager As String = ""

            Dim strDepartment As String = ""

            Dim strOffice As String = ""

            Dim strTitle As String = ""

            Dim strMail As String = ""

            For Each objResult In DirSearchResultCol

                With objResult

                    If Not (.Properties("displayname") Is Nothing) Then

                        If .Properties("displayname").Count > 0 Then

                            strName = .Properties("displayname")(0).ToString


                        End If

                    End If

                    If Not (.Properties("telephoneNumber") Is Nothing) Then

                        If .Properties("telephoneNumber").Count > 0 Then

                            strExt = .Properties("telephoneNumber")(0).ToString

                        End If

                    End If

                    If Not (.Properties("manager") Is Nothing) Then

                        If .Properties("manager").Count > 0 Then

                            strManager = .Properties("manager")(0).ToString


                            strManager = strManager.Substring(3, strManager.IndexOf(",") - 3).Trim

                        End If

                    End If

                    If Not (.Properties("department") Is Nothing) Then

                        If .Properties("department").Count > 0 Then

                            strDepartment = .Properties("department")(0).ToString

                        End If

                    End If

                    If Not (.Properties("physicalDeliveryOfficeName") Is Nothing) Then

                        If .Properties("physicalDeliveryOfficeName").Count > 0 Then

                            strOffice = .Properties("physicalDeliveryOfficeName")(0).ToString

                        End If

                    End If

                    If Not (.Properties("title") Is Nothing) Then

                        If .Properties("title").Count > 0 Then

                            strTitle = .Properties("title")(0).ToString

                        End If

                    End If

                    If Not (.Properties("mail") Is Nothing) Then

                        If .Properties("mail").Count > 0 Then

                            strMail = .Properties("mail")(0).ToString

                        End If

                    End If

                End With


                dt.Rows.Add(strName, strExt, strManager, strDepartment, strOffice, strTitle, strMail)


            Next



            Return dt


        End Function


    From here the main form uses the information and displays it in the label controls

     Dim dt As DataTable

                    dt = New DataTable

                    dt = GetUserInfoFromADDS(GetUsername, "")

     lblDisplayName.Text = .Rows(0).Item("displayname").ToString

    dt.Dispose()


    All of this cod sits within default.aspx. Is this code related or something on my server perhaps?

    Thanks


    Regards




    Tuesday, May 25, 2010 5:54 AM

Answers

  • User1241303409 posted

    I've just found the problem, hopefully you wont make the same mistake.

    This code was running on the master page without any kind of caching. The page it was loading with the master page (default.aspx) did have a output cache. I removed this and now it works fine. 

    I wasnt aware that the output cache for a page would have effect on the master page.

    Thanks for looking into.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 2, 2010 6:12 AM

All replies

  • User197322208 posted

    the code seems ok

    1. Do you have enabled Windows Authentication and remove "Anonoymous access" on site?

    2. Could you monitor ( record to a log, or other) before the line

    lblDisplayName.Text = .Rows(0).Item("displayname").ToString 

    if

    .Rows.Count > 1

    and record also the user name ?

    3. I would suggest replacing

    Return My.User.Name.ToUpper.Replace("RAYMARINE\", "").ToString

    with

    Return HttpContext.Current.Identity.Name.Replace("RAYMARINE\", "").ToString

     

     

    Tuesday, May 25, 2010 7:21 AM
  • User1241303409 posted

    Hi,

     Thanks for your help, yep the server and all directories are only windows authentication, im glad the code looks fine, i will update the username function and try and log that scenario

    Cheers

    Tuesday, May 25, 2010 7:52 AM
  • User1241303409 posted

    Ok i have checked this code, it turns out, the code to query the data works just fine, but the problem lies within the HttpContext.Current.User.Identity.Name code.

    If i have the page open by two different users at the same time, then refresh the pages at the same time there becomes a conflict and one user ends up having the other user's user identity and so when it querys the data based on that username, both browsers end up with the same user's information.

    I have no caching/output caching enabled on the page either


    Thanks

    Wednesday, June 2, 2010 5:22 AM
  • User1241303409 posted

    I've just found the problem, hopefully you wont make the same mistake.

    This code was running on the master page without any kind of caching. The page it was loading with the master page (default.aspx) did have a output cache. I removed this and now it works fine. 

    I wasnt aware that the output cache for a page would have effect on the master page.

    Thanks for looking into.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 2, 2010 6:12 AM