Change Mapping of fields of CreateUserWizard control with membership provider asp.net 4.0

我只是一个虾纸丫 提交于 2019-12-12 03:00:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!