0

我正在做一个项目,我有一个任务来创建用户(使用 CreateUserWizard 控件)。我必须将用户保存在 SQL Server 数据库中的特定表中。

还要创建一个登录名(使用登录控件),在登录名通过身份验证后,它应该保存配置文件信息。

到目前为止,我已经创建了继承 ProfileBase 的 CustomProfile。还创建了 3 个 aspx 页面。

  1. 登录.aspx
  2. 创建用户.aspx
  3. 默认.aspx

我的 CustomProfile 如下所示:

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(); }
    }
}

我已经使用aspnet_regsql.exe它在 sql server 中创建了多个表并将数据存储在这些表中并且工作正常。我想将信息保存到我的表格中,例如。tblUserInfo. 我应该如何进行?我检查了多个论坛,但没有运气。

任何帮助深表感谢。

4

1 回答 1

1

首先 aspnet_regsql.exe 已经过时了。您可能要考虑使用ASP.Net Universal Providers

我假设您的问题是将信息保存到我的表格中,例如。tblUserInfo

您可以收集用户信息并自行保存,而不是使用 CreateUserWizard。

1.创建一个tblUserInfo表(ASP.Net Profile的替代方案)

2、创建用户后将UserInfo插入tblUserInfo

<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;

3. 如何让登录用户可以使用 UserInfo?

于 2012-05-10T20:49:01.287 回答