I am working on a project where I got a task to create a user (using the CreateUserWizard control). I have to save the user in a specific table in the SQL Server database.
Also create a login (using the Login control) and after the login is authenticated it should hold the profile information.
So far, I have created CustomProfile that inherites the ProfileBase. Also have created 3 aspx pages.
My CustomProfile looks like the following:
public class UserProfile : ProfileBase
{
static public UserProfile CurrentUser
{
get
{
return (UserProfile)(ProfileBase.Create(Membership.GetUser().UserName));
}
}
public string FirstName
{
get { return (string)base["FirstName"]; }
set { base["FirstName"] = value; Save(); }
}
public string LastName
{
get { return (string)base["LastName"]; }
set { base["LastName"] = value; Save(); }
}
public DateTime DateOfBirth
{
get { return (DateTime)base["DateOfBirth"]; }
set { base["DateOfBirth"] = value; Save(); }
}
public ContactInfo Contact
{
get { return (ContactInfo)base["Contact"]; }
set { base["Contact"] = value; Save(); }
}
}
I have used aspnet_regsql.exe
and it created multiple tables in the sql server and storing the data in those tables and is working fine. I would like to save the information into my table eg. tblUserInfo
. How should I proceed? I checked multiple forums but no luck.
Any help is much appreciated.
First of all aspnet_regsql.exe is outdated. You might want to consider using ASP.Net Universal Providers.
I assume your question is save the information into my table eg. tblUserInfo
Instead of using CreateUserWizard, you can collect the user information and save it by yourself.
1. Creating a tblUserInfo table (alternative solution to ASP.Net Profile)
2. Inserting UserInfo into tblUserInfo after creating a user
<asp:TextBox ID="UsernameTextBox" runat="Server" />
<asp:TextBox ID="EmailTextBox" runat="Server" />
<asp:TextBox ID="PasswordTextBox" runat="Server" />
<asp:TextBox ID="PasswordQuestionTextBox" runat="Server" />
<asp:TextBox ID="PasswordAnswerTextBox" runat="Server" />
<asp:TextBox ID="FirstNameTextBox" runat="Server" />
<asp:TextBox ID="LastNameTextBox" runat="Server" />
string username = UsernameTextBox;
string password = PasswordTextBox.text;
string email = EmailTextBox.text;
string passwordQuestion = PasswordQuestionTextBox.text;
string passwordAnswer = PasswordAnswerTextBox.text;
bool isApproved = true;
MembershipCreateStatus status;
MembershipUser membershipUser = System.Web.Security.Membership.CreateUser(
username, password, email, passwordQuestion, passwordAnswer, isApproved, out status);
if (status != MembershipCreateStatus.Success)
throw new Exception(status.ToString());
// Save the rest of the user info to tblUserInfo with userId
Guid userId = (Guid)membershipUser.ProviderUserKey;