Solved

Get user from LDAP

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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 …

772 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