0

以下は使用したコードです。「44 行目」が問題の領域です。

var groups = p.GetAuthorizationGroups();

Index was outside the bounds of the array正常に機能してから約1日後にエラーが発生します。この最後のビットは、状況の本当の鼻くそであるようです. 範囲外のエラーをスローするための解決済みの問題をたくさん見つけましGetAuthorizationGroupsたが、ほとんどが機能するシステムに関する解決策を見つけることができません。

ありとあらゆる助けをいただければ幸いです。そして、この投稿に関する問題を修正するために最善を尽くします。

編集: 現在、エラーをクリアする唯一の方法は、Web サーバーを再起動することです。IIS を再起動するだけでは問題は解決しません。

public override String[] GetRolesForUser(String username)
{
    //Check to see if role are already cached in Session variable
    if ((string[])System.Web.HttpContext.Current.Session["Roles"] == null)
    {
        //Create an ArrayList to store our resultant list of groups.
        ArrayList results = new ArrayList();
        //PrincipalContext encapsulates the server or domain against which all operations are performed.
        using (PrincipalContext context = new PrincipalContext(ContextType.Domain, null, "blargh.com"))
        {
            try
            {
                //Create a referance to the user account we are querying against.
                UserPrincipal p = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);
                //Get the user's security groups.  This is necessary to
                //return nested groups, but will NOT return distribution groups.
                var groups = p.GetAuthorizationGroups();
                foreach (GroupPrincipal group in groups)
                {
                    results.Add(group.SamAccountName);
                }
            }
            catch (Exception ex)
            {
                throw new ProviderException("Unable to query Active Directory.", ex);
            }
        }
        // Store roles in Session for caching
        System.Web.HttpContext.Current.Session["Roles"] = results.ToArray(typeof(String)) as String[];
    }
    return (string[])System.Web.HttpContext.Current.Session["Roles"];
}
4

0 に答える 0