枚举Active Directory组时ArgumentOutOfRangeException

时间:2013-10-22 12:42:42

标签: c# asp.net active-directory

枚举用户Active Directory组时,我收到以下错误

  

System.Web.HttpUnhandledException(0x80004005):类型异常   抛出'System.Web.HttpUnhandledException'。 --->   System.ArgumentOutOfRangeException:索引超出范围。一定是   非负面且小于集合的大小。

这是我的代码:

internal static void admincheck(string username)
        {
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "EDIT");
            using (UserPrincipal user = UserPrincipal.FindByIdentity(ctx, username))
            {
                System.DirectoryServices.AccountManagement.PrincipalSearchResult<Principal> groupList = user.GetGroups();
                foreach (GroupPrincipal @group in groupList)
                {
                    if (@group.Name == "students") { System.Web.HttpContext.Current.Response.Redirect("no_access.aspx"); }
                }
            }
        }

有什么想法吗?谢谢

完整堆栈跟踪:

  

System.Web.HttpUnhandledException(0x80004005):抛出了类型为“System.Web.HttpUnhandledException”的异常。 ---&GT; System.ArgumentOutOfRangeException:索引超出范围。必须是非负数且小于集合的大小。参数名称:System.DoloryServices.AccountManvices.AccountManvices.AccountManvices.ADDNLinkedAttrSet.MoveNext中System.DirectoryServices.ResultSerpert.AccountManagement.ADDNLinkedAttrSet.MoveNextMemberSearcher()的System.DirectoryServices.ResultPropertyValueCollection.get_Item(Int32索引)处的System.Collections.ArrayList.get_Item(Int32索引)处的索引()位于System.Web.UI.Page.ProcessRequestMain(System.Web.UI.Page.ProcessRequestMain)的System.Web.UI.Control.LoadRecursive()的TechnicalToolkit.toolkit.admincheck(String username)上的System.DirectoryServices.AccountManagement.FindResultEnumerator`1.MoveNext()位于System.Web.UI.Page.ProcessRequestMain(布局includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)System.Web.UI.Page.ProcessRequest(布局includeStagesBeforeAsyncPoint,System.Web.UI.Page.HandleError(Exception e)处的includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)系统的System.Web.UI.Page.ProcessRequest(HttpContext context)上的System.Web.UI.Page.ProcessRequest()处的布尔includeStagesAfterAsyncPoint) System.Web.HttpApplication.ExecuteStep中的.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()(IExecutionStep step,Boolean&amp; completedSynchronously)

0 个答案:

没有答案