当前位置: 首页 > 编程语言 > C#

UserPrincipals.GetAuthorizationGroupsAnerroroccurredwhileenumeratinggroups(1301),无法解析组的SID以共享

时间:2023-04-10 13:23:41 C#

UserPrincipals.GetAuthorizationGroups枚举组时发生错误(1301)。组的SID无法解析背景:我一直在使用UserPrincipal.GetAuthorizationGroups一段时间来检查2个不同应用程序的权限。他们已经好几年了。最近一些用户遇到了标题中提到的错误(System.DirectoryServices.AccountManagement.PrincipalOperationException),而其他用户则没有。我怀疑这可能与在WindowsServer2012上运行的新域控制器有关,因为问题是在添加它们后的第二天开始的。完整错误如下:Exception:System.DirectoryServices.AccountManagement.PrincipalOperationException:Anerror(1301)occurredwhileenumeratinggroups。无法解析组的SID。在System.DirectoryServices.AccountManagement.SidList.TranslateSids(Stringtarget,IntPtr[]pSids)在System.DirectoryServices.AccountManagement.SidList..ctor(SID_AND_ATTR[]sidAndAttr)在System.DirectoryServices.AccountManagement.AuthZSet..ctor(Byte[]userSid,NetCredcredentials,ContextOptionscontextOptions,StringflatUserAuthority,StoreCtxuserStoreCtx,ObjectuserCtxBase)在System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ…p)在System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroups使用了DirectorySearcher的替代方法:varallDomains=Forest.GetCurrentForest().Domains.Cast();varallSearcher=allDomains.Select(domain=>{DirectorySearchersearcher=newDirectorySearcher(newDirectoryEntry("LDAP://"+domain.Name));searcher.Filter=String.Format("(&(&(objectCategory=person)(objectClass=user)(userPrincipalName=*{0}*)))","当前用户登录名");return搜索器;});vardirectoryEntriesFound=allSearcher.SelectMany(searcher=>searcher.FindAll().Cast().Select(result=>result.GetDirectoryEntry()));varmemberOf=directoryEntriesFound.Select(entry=>{使用(entry){returnnew{Name=entry.Name,GroupName=((object[])entry.Properties["MemberOf"].Value).Select(obj=>obj.ToString())};}});foreach(varuserinmemberOf){foreach(vargroupNameinuser.GroupName){if(groupName.Contains("GrouptoFind")){//如果用户在该组中则执行某些操作}}}检查这个答案:UserPrincipals.GetAuthorizationGroups升级到Server2012域控制器后发生枚举组错误(1301)MS修复http://support.microsoft.com/kb/2830145我有同样的异常。如果有人不想使用“LDAP”,请使用此代码。因为我有嵌套组,所以我使用了GetMembers(true),它比GetMembers()花费的时间稍长。或者从这里下载修复,比如@Tilo:http://support.microsoft.com/kb/2830145以上是C#学习教程:UserPrincipals.GetAuthorizationGroupsAnerroroccurredwhileenumeratinggroups(1301)。该组的SID无法解析所有共享的内容。如果对大家有用,需要了解更多C#学习教程,希望大家多多关注——publicboolIsMember(UserPrincipaluser,stringgroupName){);vargroup=GroupPrincipal.FindByIdentity(context,groupName);if(group==null){//不存在}else{if(group.GetMembers(true).Any(member=>user.SamAccountName.ToLower()==member.SamAccountName.ToLower())){returntrue;}}}catch(Exception异常){//异常}returnfalse;}本文收集自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除。如需转载请注明出处: