I am having an issue using the GetAuthorizationGroups method of the UserPrincipal class in a web application.
Using the following code, I am receiving \"While trying to
I dealt with this same problem. See discussion on similar question. https://stackoverflow.com/a/8347817/2012977
Solution is below:
public List GetGroups(string userName)
{
var result = new List();
PrincipalContext ctx = GetContext(); /*function to get domain context*/
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, userName);
if (user != null)
{
PrincipalSearchResult groups = user.GetAuthorizationGroups();
var iterGroup = groups.GetEnumerator();
using (iterGroup)
{
while (iterGroup.MoveNext())
{
try
{
Principal p = iterGroup.Current;
result.Add((GroupPrincipal) p);
}
catch (PrincipalOperationException)
{
continue;
}
}
}
}
return result;
}