What's dot NET
Home ] Access - Start Here ] Excel In Depth ] MS Office ] Visio Info ] Creating Web Pages ] Technical References ] Viruses ] Points of View ] Gadgets ] Just Links ] Monash ]

   Search this site or the web       powered by FreeFind
 
  Site search Web search

Participate in Ananda's Discussions
Post a message

Monitor page
for changes
    
   it's private  

by ChangeDetection

Up
ASPdotNET
ADOdotNET

Microsoft's .NET

I've been going around, telling people about .NET being ultimately an OS neutral programming framework into which you plug in any language that you feel like porting. That way, Microsoft can leap out of relying purely on Windows and into Linux if the 'nix revolution ever generates cash for desktop apps. See Mono::

System.DirectoryServices

There have been various failures to even get this Assembly properly referenced in the ASP.NET project - it is not referenced by default even though it is a standard Assembly that comes with the .NET framework.

Mark Nicholson kindly spent some time researching and came up with the following line:

<%@Assembly Name="System.DirectoryServices, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>

You can put this at the top of your .aspx page or into your global.asax.

This Assembly as far as I can see, is a wrapper over ADSI. With ADSI, I could authenticate to this Netscape LDAP Server. However, searching for an entry was difficult or impossible because ADSI has no LDAPSearch function.

Anyway, this time, I'm not interested in an ADSI interface, I want to do a System.DirectoryServices call. In particular, authenticated binding. My current code goes thus:


Dim strServerDNS As String = "serverdnsname"

Dim strUserDN As String = "CN=Joe Bloggs, O=org, C=AU"

Dim strPassword As String = "xxx"

Dim strLDAPPath As String = "LDAP://" & strServerDNS & "/" & strUserDN

Dim objDirEntry As New System.DirectoryServices.DirectoryEntry(strLDAPPath)

With objDirEntry

    .Username = strUserDN

    .Password = strPassword

     .AuthenticationType = DirectoryServices.AuthenticationTypes.ServerBind

End With

Try

   Me.txtResult.Text = objDirEntry.Properties(Me.txtProperty.Text).Value

Catch Err as Exception

   Me.txtResult.Text = "Get Property Failed: " & Err.Message

End Try


Notes:

  • Blank password causes successful anonymous bind.
  • Wrong password raises an error when you try to retrieve the first LDAP property of the entry - "Logon failure: unknown user name or bad password"
  • Wrong User DN raises a different error - "There is no such object on the server"
  • Wrong Server DNS name raises a different error.

i