I'm working on a site that uses Active Directory for authentication. I want to display certain menu items based on the users' group membership. How do I do this? I've tried tons of examples from around the Internet, but nothing is working. I'm guessing that I'm missing something relatively simple and probably has to do with the path that I'm using.
As a test, I tried this bit of code to see if I could get the details of a user:
What should the path be if I'm trying to find the group/OU membership for a user named "jdoe" on domain "mydomain.mycompany.com"? The user is in an OU off the root named "MyCompany Users". It hought that it would be something like this:
but it doesn't appear to work. Any idea as to what I'm doing wrong?
As a test, I tried this bit of code to see if I could get the details of a user:
Code:
Private Sub Test()
' Bind to a specific user.
Dim path As String
path = "LDAP://CN=User Name,CN=users, DC=fabrikam,DC=com"
Dim entry As New DirectoryEntry(path)
' Create a DirectorySearcher object.
Dim mySearcher As New DirectorySearcher(entry)
mySearcher.SearchScope = SearchScope.Base
' Use the FindOne method to find the user object.
Dim resEnt As SearchResult = mySearcher.FindOne()
Dim propKey As String
For Each propKey In resEnt.Properties.PropertyNames
' Display each of the values for the property
' identified by the property name.
Dim prop As Object
For Each prop In resEnt.Properties(propKey)
Debug.Print("{0}:{1}", propKey, [prop].ToString())
Next prop
Next propKey
End Sub
What should the path be if I'm trying to find the group/OU membership for a user named "jdoe" on domain "mydomain.mycompany.com"? The user is in an OU off the root named "MyCompany Users". It hought that it would be something like this:
Code:
LDAP://CN=jdoe,CN=MyCompany Users, DC=mydomain, DC=mycompany, DC=com