Solved

How get access to LDAP Class.vb file

Posted on 2006-07-21
2
587 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript in a user control not working 17 69
Json and asp.net mvc 2 46
How can I build my own IDE using ASP.NET MVC? 2 34
Error on Add method 1 38
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

20 Experts available now in Live!

Get 1:1 Help Now