I'm trying this code - what is in the IF 1=1 THEN block - trying to enhance this backend ASP.Net / IIS code to handle AD Group Membership and not just Username/Password validation. I am getting no where - returning an error of: 0x80005000 - which is some unexpected AD error. Well - I could of told them that - I'm clueless here. I want to see if the USERNAME that was just validated for credentials, also has a group of "Census App" - or maybe "domain\Census App".

I tried IsMemberOf() method and got same error code.

I am running this code on a production client server - so all debugging is taking place via LogOutput calls to write to a .Log file.

Code:
If Not UserValid Then
    Dim domainContext As PrincipalContext
    If pcUN = "" Then
        domainContext = New PrincipalContext(ContextType.Domain, pcDomain, pcContainer)
    Else
        domainContext = New PrincipalContext(ContextType.Domain, pcDomain, pcContainer, pcUN, pcPW)
    End If
    If domainContext.ValidateCredentials(credUN, credPW) Then
        If blnDebugLogin Then LogOutput("10b:@UserValid")
        If 1 = 1 Then
            Dim userContext As UserPrincipal = UserPrincipal.FindByIdentity(domainContext, credUN)
            LogOutput("10b2x")
            Dim groups As PrincipalSearchResult(Of Principal) = userContext.GetGroups()
            For Each p As Principal In groups
                If TypeOf p Is GroupPrincipal Then
                    LogOutput("10b2:" & CType(p, GroupPrincipal).ToString())
                End If
            Next
            UserValid = True
        Else
            UserValid = True
        End If
    Else
        If blnDebugLogin Then LogOutput("10c:@ValidateCredentials false")
        LogOutput("Log in failure (ValidateCredentials false): " & loginUsername & " " & credUN)
    End If
End If
End If