I 'm working on adding security to an internal web app. I'm trying to program it to check the groups the logged in user belongs to. If they belong to the required group(s) then the program will give the user access.
I'm making it so members of TELMIS will have admin access. When I try to login it queries for my groups but it returns everything except TELMIS. I figured it may be because TELMIS is set as my primary group in AD. So I changed my primary group to another group. Then, TELMIS is returned but the one I set to primary isn't. I don't understand why it won't return the primary group in the list of groups. Can someone explain and help me modify my code to get this to work.
Using de As New DirectoryEntry("LDAP://" + MyDomain)
Using deSearch As New DirectorySearcher()
deSearch.PageSize = 8000
deSearch.SearchRoot = de
deSearch.Asynchronous = True
deSearch.Filter = "(&(objectClass=user)(userprincipalname=" + Username() + "))"
Dim result As SearchResult = deSearch.FindOne()
If result Is Nothing Then
If result.Properties.Contains("memberof") Then
For Each item In result.Properties("memberof") ' collection
Dim value As String = item.ToString()
If value.Contains("CN=TELMIS") Then