ASP LDAP Authentication

Posted on 2004-11-08
Last Modified: 2008-03-17
I've got this code to authenticate against our Novell LDAP server for ASP.NET:

Imports System.DirectoryServices
Public Function IsAuthenticated(ByVal szUser As String, ByVal szPassword As String) As Boolean
 If szUser = "" Then szUser = "none"
 If szPassword = "" Then szPassword = "none"
 Dim strServerDNS As String = "LINLDP2"
 Dim strUserDN As String = "cn=" & szUser & ", ou=people, o=ha"
 Dim strLDAPPath As String = "LDAP://" & strServerDNS & "/" & strUserDN
 Dim objDirEntry As New System.DirectoryServices.DirectoryEntry(strLDAPPath)  
 Dim szTemp As String
 With objDirEntry
   .Username = strUserDN
   .Password = szPassword
   .AuthenticationType = DirectoryServices.AuthenticationTypes.ServerBind
 End With
  szTemp = objDirEntry.Properties("cn").Value
  Catch ex As Exception
  Return False
 End Try
 Return True
 Catch ex As Exception
 Return False
End Try

End Function

I was wondering if a solution this easy exists in ASP? Please provide code, thx!
Question by:sehenkel
    LVL 7

    Expert Comment

    LVL 7

    Expert Comment

    LVL 26

    Accepted Solution

    You can re-use this ASP.Net code in your ASP application, using a CCW (Com Component Wrapper). The idea is to register the assembly with regAsm.exe to use it as if it were a Com Object or an ActiveX
    To do this

    - create a new class library in visual studio .net 2003
    - add the required imports statements
    inside the class paste the code your provided above for the public function isAuthenticated
    - compile the class as a dll assembly (release version)
    - copy the dll to the windows\system32 directory
    - use the Visual Studio .net 2003 command prompt and run
    regAsm c:\windows\system32\YourAssembly.dll

    then in you ASP code you can write

    dim obj
    set obj = Server.CreateObject("YourAssembly.YourClassName")
    if obj.IsAuthenticated(user, password) then
    end if
    set obj = nothing



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now