Solved

Get user from LDAP

Posted on 2006-07-04
3
1,614 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

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

12 Experts available now in Live!

Get 1:1 Help Now