c# - GroupPrincipal throws argument exception -
i have static method validate, if user in adgroup or not.
method looks like:
public static bool isuserinadgroup(string groupname, string name) { if (string.isnullorempty(groupname) || string.isnullorempty(name)) { return false; } // create domain context var ctx = new principalcontext(contexttype.domain, configuration.getvalue("ad")); // find group in question var group = groupprincipal.findbyidentity(ctx, groupname); // find user var user = userprincipal.findbyidentity(ctx, name); if (user != null && group != null) { if (user.ismemberof(group)) { return true; } return false; } return false; }
i wrote unittest method , works fine. when call method wpf application, i've got exception:
what doing wrong?
Comments
Post a Comment