ASP LDAP Authentication

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
Try
 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
 Try
  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!
sehenkelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

suramsureshbabuCommented:
0
HilaireCommented:
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

HTH

Hilaire
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.