Solved

Get user from LDAP

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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