Click here to Skip to main content
16,019,593 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a DropDown, If user selects any item from list, then some labels, grid on my asp.net page will populate data from sql database.

My problem is that I want to display data based on the user who is logged in.
For validating the user, I am using directoryservices. My code to validate login users is below for reference. Let me know using this code how can I display data in label/grid based on who is logged in.

Public Class PRmain

    Inherits System.Web.UI.Page

    'To find login username and domain

    Dim domain As String = Me.Page.User.Identity.Name.Split("\".ToCharArray())(0)

    Dim username As String = Me.Page.User.Identity.Name.Split("\".ToCharArray())(1)

    'Find if the user is in a group

    Public Function IsInGroup(ByVal context As HttpContext, ByVal group As String) As Boolean

        Return context.User.IsInRole(group)

    End Function

    'Find all groups the user belongs to

    Public Function GetUserMemberships() As ArrayList

        Dim results As ArrayList = New ArrayList()

        Dim myDE As New System.DirectoryServices.DirectoryEntry("LDAP://mysite.com")

        Dim mySearcher As New DirectorySearcher(myDE)

        mySearcher.Filter = "sAMAccountName=" & username

        mySearcher.PropertiesToLoad.Add("memberOf")

        Dim propertyCount As Integer

        Try

            Dim myresult As SearchResult = mySearcher.FindOne()

            propertyCount = myresult.Properties("memberOf").Count

            Dim dn As String

            Dim commaIndex As Integer

            Dim equalsIndex As Integer

            For i As Integer = 0 To propertyCount - 1

                Try

                    dn = myresult.Properties("memberOf")(i).ToString

                    equalsIndex = dn.IndexOf("=", 1)

                    commaIndex = dn.IndexOf(",", 1)

                    results.Add(Trim(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1)).ToUpper())

                Catch ex As Exception

                    ' there was an error, this membership will not be included

                End Try

            Next

        Catch ex As Exception

            'they are still a good user just does not 

            'have a "memberOf" attribute so it errors out.

        End Try

        Return results

    End Function

End Class
Posted
Updated 10-Dec-10 3:57am
v2
Comments
JF2015 10-Dec-10 9:57am    
Edited to improve spelling and code formatting.
Dave Kreskowiak 10-Dec-10 13:32pm    
Display WHAT data in labels or a grid?
Rohit.Net100 10-Dec-10 14:41pm    
Firstly, i want to check who log in on my page using directoryservices. Secondly according to log in user, i want to populate my data from sql database on label/grid controls using databinding.
Now my question is which way i will do this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900