Solved

How get access to LDAP Class.vb file

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

763 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