1

I just create Membership management program, this program can create user one by one and it can import data from text file as well. When I import data from text file, it can create around 30 user before timeout, after I debug it take nearly 1 sec for each CreateUser call.

I want to know, how can I improve performance when I create large number of aspnet user.

Anonymous
  • 9,366
  • 22
  • 83
  • 133

1 Answers1

1

Solution1:

  1. Get all data from user table into dataset ds in table "User"
  2. Get all data from member table into table "Member" in the same dataset ds
  3. Create a relationship between the two tables on field userid
  4. Run a loop on each row of table User
  5. For each user call Membership.CreateUser with UserName and Password as parameters
  6. Get all child rows for the current user DataRow.GetChildRows
  7. For each childrow returned, call Roles.AddUserToRole with username and rolename as parameters (add only if the role is active)
    Taken from here.

Solution 2:

  1. Download Peter Keller's Membership Editor
  2. Create a SpreadSheet with these columns: UserName,password, and email.
    Import this excel file to this database as table: yourUsers$
  3. Create a Winforms application, Add a button to form and paste this code in its click event:

    protected void batchInsertButton_Click(object sender, EventArgs e)
    {
    string strConn = ConfigurationManager.ConnectionStrings["1ConnectionString"].ConnectionString;
    string strSQL = "SELECT * FROM yourUsers$";
    
    SqlConnection myConnection = new SqlConnection(strConn); 
    
    myConnection.Open();
    
    SqlCommand myCommand = new SqlCommand(strSQL,myConnection);
    
    SqlDataReader myReader; 
    
    
    myReader = myCommand.ExecuteReader(); 
        while (myReader.Read()) {
    
            ObjectDataSourceMembershipUser.InsertParameters["UserName"].DefaultValue = myReader["UserName"].ToString();//TextBoxUserName.Text; ;
            ObjectDataSourceMembershipUser.InsertParameters["password"].DefaultValue = myReader["password"].ToString();//TextBoxPassword.Text;
            ObjectDataSourceMembershipUser.InsertParameters["passwordQuestion"].DefaultValue ="your qestion";//TextBoxPasswordQuestion.Text;
            ObjectDataSourceMembershipUser.InsertParameters["passwordAnswer"].DefaultValue = "your answer";//TextBoxPasswordAnswer.Text;
            ObjectDataSourceMembershipUser.InsertParameters["email"].DefaultValue = myReader["email"].ToString();//TextBoxEmail.Text;
            ObjectDataSourceMembershipUser.InsertParameters["isApproved"].DefaultValue = "true";//CheckboxApproval.Checked == true ? "true" : "false";
    
    ObjectDataSourceMembershipUser.Insert();
    
    
    //hard code this user role
    Roles.AddUserToRole(myReader["UserName"].ToString(), "NormalUser"); 
    
            } 
    myConnection.Close();
    
    GridViewMemberUser.DataBind();
    GridViewRole.DataBind();
    }  
    

Taken from here.

Kamyar
  • 18,639
  • 9
  • 97
  • 171
  • Looking through ILSpy it appears that Roles.AddUserToRole calls Roles.AddUsersToRoles. Would there be a benefit to just build a string array of users (less commas) and a one element array for NormalUser then Add Users To Roles after Membership: `string[] normalRole = new string[] { "NormalUser"}; Roles.AddUsersToRoles(userList, normalRole); `The both methods check the Role and UserNames for validity (commas, length, null) so it will repeatedly validate "NormalUser" x number of times where x is the number of users to add. – Charles Byrne May 04 '12 at 18:29