Solved

How get access to LDAP Class.vb file

Posted on 2006-07-21
2
578 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 500 total points
Comment Utility
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
Comment Utility

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now