Member_2_1242703
asked on
Seeing if user exists in Active Directory Group
My code currently gets a users username (NT) from their computer. I want to take that name and look in AD and see if they belong to a particular group. If they do, then forward to page1.aspx. If they do not, then forward to page2.aspx. How would I do that? Here's how i'm connecting:
Dim ldapPath As String = "LDAP://155.177.96.154/OU= Sherman,OU =Fisher Controls,dc=na,dc=emersonp rocess,dc= com"
Dim filter As String = String.Format("(&(objectCl ass=user)( objectCate gory=perso n)(sAMAcco untName={0 }))", logon)
Dim entry As New DirectoryEntry(ldapPath)
Dim ldapPath As String = "LDAP://155.177.96.154/OU=
Dim filter As String = String.Format("(&(objectCl
Dim entry As New DirectoryEntry(ldapPath)
Here's using directoryservices...
Friend Shared Function IsInGroup(ByVal strUser As String) As Boolean
Dim blnReturn As Boolean = False
If strUser = "" Then
Return False
End If
Dim objSearch As New DirectorySearcher("DOMAIN NAME")
objSearch.Filter = "(objectCategory=user)(dep artment=DE PARTMENT NAME*)(!mail=zz*)"
Dim objResults As SearchResultCollection = objSearch.FindAll
If objResults.Count > 0 Then
Dim objReturn(objResults.Count - 1) As SearchResult
objResults.CopyTo(objRetur n, 0)
For Each objItem As SearchResult In objResults
If objItem.GetDirectoryEntry( ).Properti es("sAMAcc ountName") .Value = strUser Then
blnReturn = True
Exit For
End If
Next
End If
Return blnReturn
End Function
Friend Shared Function IsInGroup(ByVal strUser As String) As Boolean
Dim blnReturn As Boolean = False
If strUser = "" Then
Return False
End If
Dim objSearch As New DirectorySearcher("DOMAIN NAME")
objSearch.Filter = "(objectCategory=user)(dep
Dim objResults As SearchResultCollection = objSearch.FindAll
If objResults.Count > 0 Then
Dim objReturn(objResults.Count
objResults.CopyTo(objRetur
For Each objItem As SearchResult In objResults
If objItem.GetDirectoryEntry(
blnReturn = True
Exit For
End If
Next
End If
Return blnReturn
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.experts-exchange.com/questions/21386152/ASP-NET-Forms-Authentication-Active-Directory.html