hello this is my code could anyone help me, I want to search exact user in special group in active directory, my group name is test11 . could anyone here help me to do this.
thanks this is my code
Public Function ValidateUser(ByVal Domain As String, ByVal username As String, ByVal password As String) As Boolean
Dim strGroupDN As String
strGroupDN = "Users"
Try
Dim de As New DirectoryEntry("LDAP://" & Domain, username, password, AuthenticationTypes.Secure)
Dim srch As New DirectorySearcher(de)
' srch.Filter = "(objectClass=Group)"
'srch.SearchScope = SearchScope.Subtree
'srch.Filter = "(&(ou=hh)(cn=test11))"
srch.Filter = "(&(objectClass=user)(samAccountName=" & username & "))"
de.Invoke("Groups", New Object() {"test11"})
'srch.Filter = "(&(objectCategory=Person)(objectClass=user)(ou=hh )"
' srch.Filter = "(&(objectClass=user)(samAccountName=" & username & ")(memberOf=" & strGroupDN & "))"
Dim result As SearchResult = srch.FindOne
If Not result Is Nothing Then
Return True
Else
Return False
End If
Catch ex As Exception
Console.Write(ex.Message + ControlChars.NewLine + ex.StackTrace)
Return False
End Try
End Function
--------------------------------
From: Sara
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>Q7MXSVHElkKpSsjsO5XMUg==</Id>