Difficulty Quering Active Directory on MemberOf

Posted on 2010-01-11
Medium Priority
Last Modified: 2012-05-08
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
                    Return False
                End If

                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
                            Return True
                        End If

                End If

            End Using

        End Using

Question by:ScottMacMaster
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 15

Accepted Solution

Colosseo earned 2000 total points
ID: 26284084
Hi Scott

Basically the primary group doesnt appear in the memberof collection it is accessed sperately:

Have a look at this, http://support.microsoft.com/kb/321360

Am looking just now at how you can implement this



Author Comment

ID: 26284902
Well, I can understand not storing the primary group in the list of groups to save space.  However, why force end users to query 2 different things to find out if if a user if a member of a group.  AD could at least return the primary group amoung the list of members.  Well, I guess I just need to add code to get the primary group.  Any chance you know of a reference that shows how to do that in VB.NET not ADSI?


Author Comment

ID: 26285709
Oh, I can just use the global variable 'User'.  I've always used it to get the name of the logged in user.  I can use User.IsInRole("TELMIS") to check the users membership.  And it works whether the group is primary or not.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question