Question

I am new to membership stuff on asp.net. If I need to create a new user with extra parameter e.g firstname. Should I create a new table for those extra parameters?

If I am not using CreateUserWizard to create user, do I just use Membership.CreateUser to create the user?

Please help

Was it helpful?

Solution

After getting additional user information, such as the first name you can save this information to a custom database table.

A valid point might be storing the information in the profile. But when running through the wizard, the user is not authenticated yet, so you cannot store the information into the profile, as this is available for authenticated users only. Therefore, you either have to store it in a custom database table or include a way for the user to edit the profile after the registration process.

dbo.aspnet_Profile is the table, inside aspnetdb database, used by default for storing profiles of the users. So, in case you prefer to store in Profile, After creating the User, load the profile of the newly created user and set the custom info you gathered.

ProfileCommon p = Profile.GetProfile(strUsername);
//update the field and save
p.FirstName= txtFirstName.Text;
p.Save();

Question 2::

If I am not using CreateUserWizard to create user, do I just use
Membership.CreateUser to create the user??

Yes, it's not necessary to use CreateUserWizard to create a user. Even you can just collect some basic info like: UserName, Password only using 2 TextBoxes and create the user using the various overloaded versions of MemberShip.CreateUser() method. Check MSDN. Also, this Link created user with very basic info.

OTHER TIPS

You can use the ASP.NET Profile properties to store the extra information for the user's. You know more on this MSDN article.

There is a table called UserProfile which stores the username and user ID. This is used by the Membership.CreateUser function.

If you add to this table, the columns must be nullable otherwise it will throw an error when you try to create a new user.

An alternative is to use a separate table to store further details in. Ensure that the primary key is of type INT and is NOT auto-incremented. This way you can ensure that the ID is the same as the user ID of the UserProfile table, avoiding a 1-to-many relationship between the two tables.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top