Import users to membership

Source: Internet
Author: User
Today, I went to the customer to implement the project. I had to talk about using the demo data for testing. Later, I will temporarily import the current user. No
With a laptop, the customer's server only has an ordinary Program For general data initialization, SQL Server 2000 and Excel can solve the problem.
But now the system has introduced Asp.net membership as the user model, so the import needs to be different. The main idea is as follows: first put the user into a common text file,
Read in the program, pay attention to the Chinese encoding, and then use membership to create a user. In this way, you do not need to analyze the relationship again. In fact, the relationship between membership tables is clear.

String filename = "C: \ Name ";
// Open the file and display its content
Streamreader reader = NULL;
Try
{

Reader = new streamreader (filename, system. Text. encoding. Default );
For (string line = reader. Readline (); line! = NULL; line = reader. Readline ())
{

// General information of the registered user
String username = line;
String Password = "123456 ";
String email = username + "sf.com ";
String question = "Where is SF ";
String answer = "jiangsusuzhou ";

membershipcreatestatus status;
membershipuser newuser = membership. createuser (username. trim (), password. trim (), email. trim (), question. trim (), answer. trim (), true, out status);

// registered user Extension Information
If (status = membershipcreatestatus. success)
{< br> console. writeline ("Reg OK");
console. writeline (line);
}else
{< br> console. writeline ("Reg failed");

}
}
}
Catch (ioexception E)
{
Console. writeline (E. Message );
}
If (reader! = NULL)
Reader. Close ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.