我只是创建会员管理程序,该程序可以逐个创建用户,也可以从文本文件导入数据。当我从文本文件导入数据时,它可以在超时之前创建大约30个用户,在我调试之后每个CreateUser调用花费将近1秒。
我想知道,当我创建大量aspnet用户时,如何提高性能。
答案 0 :(得分:1)
解决方案1:
解决方案2:
创建Winforms应用程序,添加一个按钮以在其点击事件中形成并粘贴此代码:
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();
}
取自here。