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://,OU=Fisher Controls,dc=na,dc=emersonprocess,dc=com"

        Dim filter As String = String.Format("(&(objectClass=user)(objectCategory=person)(sAMAccountName={0}))", logon)

        Dim entry As New DirectoryEntry(ldapPath)

Mike MillerSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here is how I get the groups, the following link is actually for my VB.NET web project, but the code is pretty similar.  There is a function called GetGroups() which pulls the users groups based on the path (your ldapPath variable).

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)(department=DEPARTMENT NAME*)(!mail=zz*)"
            Dim objResults As SearchResultCollection = objSearch.FindAll
            If objResults.Count > 0 Then
                Dim objReturn(objResults.Count - 1) As SearchResult
                objResults.CopyTo(objReturn, 0)
                For Each objItem As SearchResult In objResults
                    If objItem.GetDirectoryEntry().Properties("sAMAccountName").Value = strUser Then
                        blnReturn = True
                        Exit For
                    End If
            End If
            Return blnReturn
        End Function
>> Seeing if user exists in Active Directory Group
You're still using the same web app, right? If the user is successfully authenticated, that means the user surely exists in your AD server.

>> ...and see if they belong to a particular group..
Dim isInRole As Boolean = HttpContext.Current.User.IsInRole("domain\HelpDesk")

Or you need more information?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.