I am trying to determine if a user is a member of an Active Directory (AD) group for an internal ASP.NET 4.0 application. The code below displays the error message "Attempting to access an unloaded appdomain" on the last line (return statement) when the user is not a member of the AD group.
public static bool IsInADGroup(string userName, string groupName) { var principalContext = new PrincipalContext(ContextType.Domain); UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, userName); if (userPrincipal == null) return false; GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(principalContext, groupName); if (groupPrincipal == null) return false; return userPrincipal.IsMemberOf(groupPrincipal); }
Any ideas on how to fix or use other workarounds?
Dave Johnson Aug 23 2018-11-23T00: 00Z
source share