问题
I am using CreateUserWizard Control with membership provider in asp.net 4.0.
In this case user name is stored in 'user name' field in aspnet_Users table.
I want to save 'user name' field in email field of aspnet_Membership table (In my case username is also email); In other words I want to change mapping of these fields.
How can I do this?
Note: My Problem is how to change mapping. Above is the only example
回答1:
You can easily achive by calling CreateUser method instead of using CreateUserWizard.
<asp:TextBox ID="EmailTextBox" runat="Server" />
<asp:TextBox ID="PasswordTextBox" runat="Server" />
<asp:TextBox ID="PasswordQuestionTextBox" runat="Server" />
<asp:TextBox ID="PasswordAnswerTextBox" runat="Server" />
string username = EmailTextBox.text; // Same as email
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());
来源:https://stackoverflow.com/questions/10268215/change-mapping-of-fields-of-createuserwizard-control-with-membership-provider-as