索引超出范围异常 - Active Directory适配器

时间:2017-08-02 17:17:29

标签: asp.net-mvc

我理解Index Out of Range Exception是什么,但是,我似乎无法弄清楚下面的Stack Trace中发生了什么。

这是一个asp.net网站,过去几年一直没有问题。我已经与系统管理员核实过,他们注意到托管网站或DC的服务器上没有任何变化。目前处于停滞状态,有关于在何处观察或开始诊断的任何想法?

[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.DirectoryServices.AccountManagement.SidList.TranslateSids(String target, IntPtr[] pSids) +1507
System.DirectoryServices.AccountManagement.SidList..ctor(SID_AND_ATTR[] sidAndAttr) +142
System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ(Principal p) +220
System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroupsHelper() +50
PayDirectory.Classes.ActiveDirectoryAdapter.IsUserAllowed(String username, IList`1 allowedgroups) in C:\Users\johndoe\Documents\Visual Studio 2010\Projects\PayDirectory\PayDirectory\Classes\ActiveDirectoryAdapter.cs:35
PayDirectory.Controllers.AccountController.CheckUser(String sessionid) in C:\Users\johndoe\Documents\Visual Studio 2010\Projects\PayDirectory\PayDirectory\Controllers\AccountController.cs:42    
lambda_method(Closure , ControllerBase , Object[] ) +108
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +188
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +29

等。

这是堆栈跟踪的开始,我可以在必要时发布整个跟踪。

基本上,应用程序获取登录到Joomla的用户的会话ID,检查广告以查看该用户是否在特定组(Principals)中并允许他们查看某些内容,否则它将声明Access被拒绝。 / p>

修改 在ActiveDirectoryAdapter类中添加“IsuserAllowed”的源代码

    public Boolean IsUserAllowed(string username, IList<string> allowedgroups)
    {
        PrincipalContext domain = new PrincipalContext(ContextType.Domain, "Redmond");

        UserPrincipal user = UserPrincipal.FindByIdentity(domain, username);

        List<GroupPrincipal> groups = new List<GroupPrincipal>();

        if (user != null)
        {
            PrincipalSearchResult<Principal> authGroups = user.GetAuthorizationGroups();

            foreach (Principal p in authGroups)
            {
                if (p is GroupPrincipal)
                {
                    groups.Add((GroupPrincipal)p);
                }
            }
        }

        string groupstring = string.Join(",", (object[])groups.ToArray());
        string[] groupnames = groupstring.Split(',');

        for (int i = 0; i < allowedgroups.Count; i++)
        {
            if (groupnames.Contains(allowedgroups[i]))
            {
                return true;
            }
        }

        return false;
    }

0 个答案:

没有答案