Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How get access to LDAP Class.vb file

Posted on 2006-07-21
2
Medium Priority
?
627 Views
Last Modified: 2012-06-27
Hi experts,

I want to get the current userInfo from different aspx pages and therefore i want to put the ldap-code into a LDAPAuthentication.vb class-file. I tried this, but could not find out what I must do to get the value from the page.



Code for LDAPAuthentication.vb
****************************************************

    Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String) As String
        Try

            Dim sPath As String = "LDAP://directory.xxxxxxx.net/OU=Users,OU=xxxxx,DC=xxxxx,DC=xxxx,DC=net"
            Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))

            Dim myDirectory As New DirectoryServices.DirectoryEntry(sPath, "xxxxxxx", "xxxxxxxxx") 'pass the user account and password for your Enterprise admin.
            Dim mySearcher As New DirectoryServices.DirectorySearcher(myDirectory)
            Dim mySearchResultColl As DirectoryServices.SearchResultCollection
            Dim mySearchResult As DirectoryServices.SearchResult
            Dim myResultPropColl As DirectoryServices.ResultPropertyCollection
            Dim myResultPropValueColl As DirectoryServices.ResultPropertyValueCollection
            'Build LDAP query
            mySearcher.Filter = "(samaccountname=" & SamAccount & ")"

            mySearchResultColl = mySearcher.FindAll()

            'I expect only one user from search result

            Select Case mySearchResultColl.Count
                Case 0
                    Return "Null"
                    Exit Function
                Case Is > 1
                    Return "Null"
                    Exit Function
            End Select



            'Get the search result from the collection
            mySearchResult = mySearchResultColl.Item(0)



            'Get the Properites, they contain the usefull info
            myResultPropColl = mySearchResult.Properties



            'displayname, mail
            'Retrieve from the properties collection the display name and email of the user
            myResultPropValueColl = myResultPropColl.Item(inType)
            Return CStr(myResultPropValueColl.Item(0))



        Catch ex As System.Exception

            'do some error return here.

        End Try


    End Function





****************************************************
at the page for example default.aspx in code behind I want only put something like this


        Dim UserAccount As String = Page.User.Identity.Name
        Dim sDisplayName As String = GetUserInfo(UserAccount, "displayName")
        lblDisplayName.Text = sDisplayName


I would be very grateful if someone could help me.
Thank you
lanter007
0
Comment
Question by:lanter007
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 total points
ID: 17152725
Hi lanter007,

Make it a shared function:

    Public Shared Function GetUserInfo(ByVal inSAM As String, ByVal inType As String) As String

Then use:

LDAPAuthentication.GetUserInfo(Me.SAMValue,Me.TypeValue)

Where SAMValue and TypeValue are replaced by the relevant pieces of information in each page.

Tim Cottee
0
 
LVL 6

Expert Comment

by:Nandakumar Sakthivel
ID: 17152727

I think you are in the right track .From all the pages you can call the function GetUserInfo by just creating an instance for LDApAuthentication class.What is the problem here..(Are you not able to get the logged in user name if so enable windows authentication inu r virtual directory)


Thanks,
Nanda
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question