Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Code Check: Active Directory

Reply
Thread Tools

Code Check: Active Directory

 
 
Rob Meade
Guest
Posts: n/a
 
      11-04-2005
Hi all,

I have some code which I cobbled together from some examples online, so its
probably wrong, although I did have it working a little while ago,
unfortunately for some reason it seems to have stopped working..nothing's
change infrastructure wise, the only thing that has changed is that my
project has been converted to VS2005 - I'm not suggesting this has caused a
problem - just stating its the only change (that I can remember!)...

The code (snipped from the class):

Public Sub Search(ByVal samaccountname As String, ByVal activeDirectory As
String)

' declare variables
Dim DirectoryEntry As DirectoryEntry = New
DirectoryEntry(LDAP://myActiveDirectory)
Dim DirectorySearcher As DirectorySearcher = New
DirectorySearcher(DirectoryEntry)
Dim Results As DirectoryServices.SearchResultCollection
Dim Result As DirectoryServices.SearchResult
Dim ResultPropertyCollection As ResultPropertyCollection
Dim ResultProperty As String

' define search properties
With (DirectorySearcher)
.Filter =
"(&(objectClass=User)(objectCategory=User)(samacco untname=" & samaccountname
& "))"
.SearchScope = SearchScope.Subtree
End With

' search
Results = DirectorySearcher.FindAll

' check number of results
If Results.Count > 0 Then

' iterate through results
For Each Result In Results

' exception handling
Try

' populate collection
ResultPropertyCollection = Result.Properties

' set class variables
Me.SetRawData(RawData)

' exception handling
Try

Me.SetGivenName(Result.Properties("givenname").Ite m(0).ToString)

Catch ex As System.NullReferenceException

Me.SetGivenName("")

End Try

' exception handling
Try

Me.SetSurname(Result.Properties("sn").Item(0).ToSt ring)

Catch ex As System.NullReferenceException

Me.SetSurname("")

End Try

End If

End Sub


This is a cut down version of what I'm currently using, but only in that I
was pulling more properties out..

Can anyone spot anything which would prevent the search from working? I'm
not getting any errors, but equally I'm not getting any values out of the ad
either - really frustrating as I was dead impressed with myself when I had
it working originally! )

Also, I'm sure this is nothing to do with it but are there any specific
ports that would need to be open on a LAN to enable this? I'd imagine I'd
have received an error somewhere if so - and I'm pretty sure that there
haven't been any infrastructure changes since it was working..

Regards

Rob


 
Reply With Quote
 
 
 
 
Rob Meade
Guest
Posts: n/a
 
      11-04-2005
Oh, I should add, it seems to be that where I test for the results > 0 - it
never is, its always 0....but as I mentioned, no error?


 
Reply With Quote
 
 
 
 
Rob Meade
Guest
Posts: n/a
 
      11-04-2005
Update:

I just ran my old .exe written in .net 1.1 and it fires up and searches
without any problems at all? Anyone got any ideas - it appears to only be a
problem because of .net 2.0

Regards

Rob


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      11-06-2005
Fixed it!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
Thunderbird filters "active" but not "active" =?ISO-8859-2?Q?Rafa=B3_=A3o=BFy=F1ski?= Firefox 5 05-18-2005 07:27 AM
Active Directory Search fails ("The directory service is unavailab ejcosta ASP .Net Security 2 10-08-2004 09:57 AM
ASP.NET and active directory code Patrick.O.Ige ASP .Net 0 08-19-2004 10:54 AM
Problem updating Active Directory from code Robin ASP .Net 1 05-27-2004 11:19 PM



Advertisments