Roles.DeleteRole()

Last post 11-13-2007 3:39 PM by bendJoe. 2 replies.

Sort Posts:

  • Roles.DeleteRole()

    11-13-2007, 2:55 PM
    • Loading...
    • bendJoe
    • Joined on 08-31-2007, 12:31 PM
    • Posts 372

     Hi,

    I have a question regarding the Roles.DeleteRole() method. As I found out the method will throw exception if there are users in this role. I tried to find a method to remove all users from  this role before calling the delete method. But I couldn't find one. What is the work around here?

    Thanks 

  • Re: Roles.DeleteRole()

    11-13-2007, 3:19 PM
    Answer
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 2:39 PM
    • Des Moines, IA
    • Posts 7,603
    • Moderator
      TrustedFriends-MVPs

    Call the overloaded constructor which accepts a throwOnPopulatedRole parameter whcih you can set to false. If false, then the rolw will be deleted whether it is empty or not.

    public static bool DeleteRole (
    	string roleName,
    	bool throwOnPopulatedRole
    )
    http://msdn2.microsoft.com/en-us/library/38h6wf59.aspx
    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
  • Re: Roles.DeleteRole()

    11-13-2007, 3:39 PM
    • Loading...
    • bendJoe
    • Joined on 08-31-2007, 12:31 PM
    • Posts 372

     Thanks I was using this workaround.

     

    protected void DeleteRoles_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < DeleteRolesList.Items.Count; i++)
            {
    
                if (DeleteRolesList.Items[i].Selected == true)
                {
                   // foreach (  string user in (Roles.GetUsersInRole(DeleteRolesList.Items[i].Text) ))
                    //{
                      //  Roles .RemoveUserFromRole (user,DeleteRolesList.Items[i].Text);
                    //}
    
                    Roles.DeleteRole(DeleteRolesList.Items[i].Text,false);
                   
                }
    
            }
            DeleteRolesList.DataSource = Roles.GetAllRoles();
            DeleteRolesList.DataBind();
        }
      
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter