Solved

How get access to LDAP Class.vb file

Posted on 2006-07-21
2
617 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

623 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