Following code returns True if the user has been added to a certain SP Group directly. However it returns False if the user is added via an AD Group. How do I fix it so that it returns true even if the user has not been added to the SP Group directly but via an AD Group?
bool userInGroup = user.Groups.Cast<SPGroup>().Any(g => g.ID == theGroup.ID);
I have tried this one it casts an exception and says the User does not exists in the Group. but the user exists in an AD Group which has been added to the SP Group.
bool userInGroup = theGroup.Users[user.LoginName] != null;