Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
[WebMethod]
   public static object ListUsersByRoles(string RoleName,int jtStartIndex = 0, int jtPageSize = 0)
   {
       try
       {
           int Id = 0;
           List<userdetails> Details = new List<userdetails>();
           MembershipUserCollection allUsers = Membership.GetAllUsers();
           var userList = Membership.GetAllUsers().OfType<MembershipUser>().ToList();
           if (RoleName == "Show All")
           {
               foreach (MembershipUser item in userList)
               {
                   var userRoles = Roles.GetRolesForUser(item.UserName);
                   Details.Add(new userdetails() { UserName = item.UserName, Email = item.Email, Comment = item.Comment, CreationDate = item.CreationDate.ToString("MM/dd/yyyy"), LastLoginDate = item.LastLoginDate.ToString("MM/dd/yyyy"), LastActivityDate = item.LastActivityDate.ToString("MM/dd/yyyy"), IsApproved = item.IsApproved.ToString(), IsOnline = item.IsOnline.ToString(), IsLockedOut = item.IsLockedOut.ToString(), Id = Convert.ToInt32(item.ProviderUserKey), RoleName = userRoles[0] });
               }
           }
           else
           {
               string[] usersInRole = Roles.GetUsersInRole(RoleName);
               foreach (MembershipUser item in userList)
               {
                   foreach (string userInRole in usersInRole)
                   {
                       if (userInRole == item.UserName)
                       {
                           var userRoles = Roles.GetRolesForUser(item.UserName);
                           Details.Add(new userdetails() { UserName = item.UserName, Email = item.Email, Comment = item.Comment, CreationDate = item.CreationDate.ToString("MM/dd/yyyy"), LastLoginDate = item.LastLoginDate.ToString("MM/dd/yyyy"), LastActivityDate = item.LastActivityDate.ToString("MM/dd/yyyy"), IsApproved = item.IsApproved.ToString(), IsOnline = item.IsOnline.ToString(), IsLockedOut = item.IsLockedOut.ToString(), Id =Convert.ToInt32(item.ProviderUserKey), RoleName = userRoles[0] });
                           break;
                       }
                   }
               }
           }
           int grpCount = Details.Count();
           var records = Details.Skip((jtStartIndex)).Take((jtPageSize));
           return new { Result = "OK", Records = records, TotalRecordCount = grpCount };
           }
           catch (Exception ex)
           {
               return new { Result = "ERROR", Message = ex.Message };
           }
   }
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jan-16 6:15am    
In what line? What is unclear in this error message? Just don't address an array element out of bounds.
—SA
BillWoodruff 2-Jan-16 6:39am    
Set break-points in your code, run the code, when you hit the break-points single-step with F11 in Visual Studio:

Find the place where the error occurs, and describe that here.
ridoy 3-Jan-16 8:10am    
So, then? are you expecting we will compile your code?

1 solution

This error occur when you are trying to access an array item which is not present in that array ? Please search for the line which throws this error and search which array index is not exist
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900