Solved

Get user from LDAP

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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