I have a situation where I need to find AD Group of a user recursively. e.g. UserA is part of Group3, Group3 is part of Group2, Group2 is part of Group1 So, UserA is part of Group3, Group2, Group1.
Now, to find all the groups for a user I have used GetAuthorizationGroups() in my code.
Dim UserP1 As UserPrincipal = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, Remote_ID)
allrecursiveUserGroups = UserP1.GetAuthorizationGroups()
The problem here is when Distinguished Name of UserPrincipal
contains special characters (a comma in my case) then it throws exception.
In my case the distinguished name is :
CN=Smith\, John,DC=mydomain,DC=com
Here backward slash has been used as escape character which is added by UserPrincipal
itself.
If Distinguished Name doesn't contain any special character the function GetAuthorizationGroups() works fine. e.g.
CN=Smith John,DC=mydomain,DC=com
What is the reason of the problem and is there any solution available for this?