Solved

Get user from LDAP

Posted on 2006-07-04
3
1,613 Views
Last Modified: 2012-06-21
Hello All,

I will ask this in three or four questions as I'll probably need help with each bit of the process. (more points! yeah!!)

Firstly, I have a web application that is currently set up on my localhost. It uses the SQLExpress to connect to my data.

My workmates can view my Applicaton on http://webdev/ (MY COMPUTER NAME ON THE NETWORK)

My files are in the shared INETPUB/WWW directory and rather than creating a separate database with userName, userEmail etc. I want to connect to the Active Directory.

My first question is "Can I Do It?"

Second, can I do this with out installing something like ADAM on my computer.

I want to connect to the AD then query and return the ActiveDirectoryMembershipUser, and use that info in my application.

I looked up LDAP connections but the only one I understood was one that created a custom provider and then used the ADAM program to create an "Active Directory Like" database. (I don't want to create another database, I want to use the existing Active Directory)

If I can do this... how do I do it?

Links to info also appreciated.

Cheers
Don
0
Comment
Question by:donaldcroswell
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
saleek earned 500 total points
ID: 17035638
hi,

It is indeed possible (assuming i understood correctly). If you want to access active directory and pull information on users, groups etc then yes, it is.

Have a look at these:

http://www.codeproject.com/vb/net/LDAP_Using_VBnet.asp

http://www.15seconds.com/issue/020730.htm

regards,

KS
0
 

Author Comment

by:donaldcroswell
ID: 17039844
Thanks Saleek

My code is below and I am getting an error.

Imports System.DirectoryServices

Partial Class login
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myDataSource As Hashtable = GetAllUsers("exchange.teacherscreditunion.com.au:389")
        'Dim en As IDictionaryEnumerator = myDataSource.GetEnumerator()
        'lblRole.Text = Response.Write(en.Value.ToString)

    End Sub

    Public Function GetAllUsers(ByVal ldapServerName As String) As Hashtable

        'To retrieve list of all  LDAP users

        'This function returns HashTable
        'ldapServerName = ldapServerName

        'Dim sServerName As String = "mail"

        Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & ldapServerName & _
              "/dc=teacherscreditunion,dc=com,dc=au")

        Dim oSearcher As DirectorySearcher = New DirectorySearcher(oRoot)
        Dim oResults As SearchResultCollection
        Dim oResult As SearchResult
        Dim RetArray As New Hashtable()

        Try
            oSearcher.PropertiesToLoad.Add("mail")
            oSearcher.PropertiesToLoad.Add("cn")
            oResults = oSearcher.FindAll()

            For Each oResult In oResults

                'If Not oResult.GetDirectoryEntry().Properties("cn").Value = "" Then
                'RetArray.Add(oResult.GetDirectoryEntry().Properties("mail").Value, oResult.GetDirectoryEntry().Properties("cn").Value)
                'End If

            Next

        Catch e As Exception

            MsgBox("Error is " & e.Message)
            Return RetArray

        End Try

        Return RetArray

    End Function
End Class

With the commented out For Each section, everything loads fine.

If I change it to the following:
                If Not oResult.GetDirectoryEntry().Properties("mail").Value = "" Then
                    'RetArray.Add(oResult.GetDirectoryEntry().Properties("mail").Value, oResult.GetDirectoryEntry().Properties("cn").Value)
                End If

I get the message box error, "The specified directory service attribute or value does not exist. I tried cn and mail but neither was found.

Any ideas what I am doing wrong?

Thanks
Don
0
 

Author Comment

by:donaldcroswell
ID: 17039878
Hey Saleek

I fixed it up with this:
        Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & ldapServerName & _
              "/cn=users,dc=teacherscreditunion,dc=com,dc=au")

for some reason I was not querying it properly.

Thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

19 Experts available now in Live!

Get 1:1 Help Now