Note that there are some explanatory texts on larger screens.

plurals
  1. POC# System.DirectoryServices.AccountManagement Unknown error (0x80005000) UserPrincipal.IsMemberOf()
    primarykey
    data
    text
    <p>Similar to the problem in the following MSDN thread: <a href="http://social.msdn.microsoft.com/Forums/en-MY/csharplanguage/thread/4c9fea6c-1d0a-4733-a8ac-e3b78d10e999" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-MY/csharplanguage/thread/4c9fea6c-1d0a-4733-a8ac-e3b78d10e999</a></p> <p>I am trying to verify whether or not a given user is a member of a group, and our existing functional solutions are too slow (13-16 seconds) and I'm trying to speed it up. I currently have:</p> <pre><code>public bool IsMemberAD(string userName, string groupName) { var pc = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain); var user = System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(pc, System.DirectoryServices.AccountManagement.IdentityType.SamAccountName, userName.ToLower()); var group = System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(pc, groupName); if (group == null || user == null) return false; return user.IsMemberOf(group); } </code></pre> <p>What makes this interesting is that it only returns an error when the user is not in the group directly, but rather a member of a group that is within the target group.</p> <p>For example:</p> <p>Steve and Sam are two users, and GroupParent and GroupChild are two groups. Steve and GroupChild are members of GroupParent. Sam is a member of GroupChild. If I call this function on (Steve, GroupParent), it returns true. If I call it on (Sam, GroupParent), I get an error. If I call it on ("fdkjskghkf", GroupParent) it returns false.</p> <p>I linked an article above with similar issues, but his solution did not work for me, I still got the same error. Ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload