c# - UserPrincipals.GetAuthorizationGroups An error (1301) occurred while enumerating the groups. The group's SID could not be resolved -
this question has answer here:
background:
i've been using userprincipal.getauthorizationgroups
while check permissions in 2 different applications. have been working fine several years. users have been getting error mentioned in title (system.directoryservices.accountmanagement.principaloperationexception
) while others have not. have suspicion might related new domain controller added running on windows server 2012 because problems started day after added. full error listed below:
exception:
system.directoryservices.accountmanagement.principaloperationexception: error (1301) occurred while enumerating groups. group's sid not resolved.
at system.directoryservices.accountmanagement.sidlist.translatesids(string target, intptr[] psids) @ system.directoryservices.accountmanagement.sidlist..ctor(sid_and_attr[] sidandattr)
at system.directoryservices.accountmanagement.authzset..ctor(byte[] usersid, netcred credentials, contextoptions contextoptions, string flatuserauthority, storectx userstorectx, object userctxbase)
at system.directoryservices.accountmanagement.adstorectx.getgroupsmemberofaz...p)
at system.directoryservices.accountmanagement.userprincipal.getauthorizationgroups
question:
how fix this?
i've found alternative using directorysearcher
:
var alldomains = forest.getcurrentforest().domains.cast<domain>(); var allsearcher = alldomains.select(domain => { directorysearcher searcher = new directorysearcher( new directoryentry("ldap://" + domain.name)); searcher.filter = string.format( "(&(&(objectcategory=person)(objectclass=user)(userprincipalname=*{0}*)))", "current user login name"); return searcher; } ); var directoryentriesfound = allsearcher.selectmany(searcher => searcher.findall() .cast<searchresult>() .select(result => result.getdirectoryentry())); var memberof = directoryentriesfound.select(entry => { using (entry) { return new { name = entry.name, groupname = ((object[])entry.properties["memberof"].value) .select(obj => obj.tostring()) }; } } ); foreach (var user in memberof) { foreach (var groupname in user.groupname) { if (groupname.contains("group find")) { // if user in group } } }
Comments
Post a Comment