• Mebership 中用户个性信息的存储方法,简单易懂,非profile (Asp.Net C#)


    首先在aspnetdb中建立这样一张表

    前台页面

    ---------------------------------------------------------------------------------------------------------------

    按钮事件的处理

    protected void Button1_Click(object sender, EventArgs e)
        {
            MembershipCreateStatus ex;//创建用户返回的错误信息
            MembershipUser newuser =  Membership.CreateUser(TextName.Text.Trim(), TextPwd.Text.Trim(), TextEmail.Text.Trim() +"@"+ DropDownListemail.SelectedValue, TextQues.Text.Trim(), TextAnswer.Text.Trim(),true,out ex);
            if (newuser == null)
            {
                Msg.Text = GetErrorMessage(ex);
            }
            else
            {

                 //newuser.ProviderUserKey  返回用户唯一标识对象
                 CreatXinx((Guid)newuser.ProviderUserKey, TextAdress.Text.Trim(), TextTel.Text.Trim(), TextPhon.Text.Trim(), TextCompany.Text.Trim(), TextCountry.Text.Trim());
                Msg.Text = "创建成功!";

                //do nothing!!
               
            }
        }

    //遍历错误类型。输出错误信息
        public string GetErrorMessage(MembershipCreateStatus status)
        {
            switch (status)
            {
                case MembershipCreateStatus.DuplicateUserName:
                    return "Username already exists. Please enter a different user name.";

                case MembershipCreateStatus.DuplicateEmail:
                    return "A username for that e-mail address already exists. Please enter a different e-mail address.";

                case MembershipCreateStatus.InvalidPassword:
                    return "The password provided is invalid. Please enter a valid password value.";

                case MembershipCreateStatus.InvalidEmail:
                    return "The e-mail address provided is invalid. Please check the value and try again.";

                case MembershipCreateStatus.InvalidAnswer:
                    return "The password retrieval answer provided is invalid. Please check the value and try again.";

                case MembershipCreateStatus.InvalidQuestion:
                    return "The password retrieval question provided is invalid. Please check the value and try again.";

                case MembershipCreateStatus.InvalidUserName:
                    return "The user name provided is invalid. Please check the value and try again.";

                case MembershipCreateStatus.ProviderError:
                    return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";

                case MembershipCreateStatus.UserRejected:
                    return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";

                default:
                    return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
            }
        }

    //向表中添加用户的信息

       public void CreatXinx(Guid UserId,string Adress,string tel,string phone,string company,string country)
        {
            public static string Aspnetdbconn = "server=.;database=aspnetdb;uid=sa;pwd=qwe2323478";
            SqlConnection conn = new SqlConnection(Aspnetdbconn);
            SqlCommand MyCommand = new SqlCommand(); 
            conn.Open();
            string sqlstr = "INSERT INTO User_xinxi(UserId,Adress,Pone,Commpany,Country,Tel) VALUES (@UserId,@Adress,@Pone,@Commpany,@Country,@Tel)";
            MyCommand.Connection = conn;
            MyCommand.CommandText = sqlstr;
            MyCommand.Parameters.AddWithValue("@UserId", UserId);
            MyCommand.Parameters.AddWithValue("Adress", Adress);
            MyCommand.Parameters.AddWithValue("Pone", phone);
            MyCommand.Parameters.AddWithValue("Commpany", company);
            MyCommand.Parameters.AddWithValue("Country", country);
            MyCommand.Parameters.AddWithValue("Tel", tel);
            MyCommand.ExecuteNonQuery();
            conn.Close();
        }

    下面为登陆页前台代码,可以忽略。可供朋友复制<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table cellpadding="1" cellspacing="1" style=" 523px; height: 199px; background-color: #cc6600">
                <tr>
                    <td align="right" style=" 132px">
                    </td>
                    <td align="center" style=" 264px">
                        User</td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Username</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextName" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Password</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextPwd" runat="server" BackColor="#FFC0C0" TextMode="Password"
                            Width="149px"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                    </td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextPwd2" runat="server" BackColor="#FFC0C0" TextMode="Password"
                            Width="149px"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 26px">
                        Quesqtion</td>
                    <td style=" 264px; height: 26px">
                        <asp:TextBox ID="TextQues" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 26px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 26px">
                        Answer</td>
                    <td style=" 264px; height: 26px">
                        <asp:TextBox ID="TextAnswer" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 26px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Email</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextEmail" runat="server" BackColor="#FFC0C0" Width="114px"></asp:TextBox>@<asp:DropDownList
                            ID="DropDownListemail" runat="server" BackColor="#FFC0C0" Width="99px">
                            <asp:ListItem Value="163.com"></asp:ListItem>
                            <asp:ListItem Value="yahoo.com.cn"></asp:ListItem>
                        </asp:DropDownList></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 13px">
                        Adress</td>
                    <td style=" 264px; height: 13px">
                        <asp:TextBox ID="TextAdress" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 13px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 8px">
                        Tel</td>
                    <td style=" 264px; height: 8px">
                        <asp:TextBox ID="TextTel" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 8px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 20px">
                        Phone</td>
                    <td style=" 264px; height: 20px">
                        <asp:TextBox ID="TextPhon" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 20px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Company</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextCompany" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Country</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextCountry" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                    </td>
                    <td align="center" style=" 264px">
                        <asp:Button ID="Button1" runat="server" BackColor="#FFE0C0" OnClick="Button1_Click"
                            Text="OK" Width="51px" />
                        <input id="Reset1" style="background-color: #ffe0c0" type="reset" value="reset" /></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="3" rowspan="2">
                        <asp:Label ID="Msg" runat="server"></asp:Label></td>
                </tr>
                <tr>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 21px">
                    </td>
                    <td style=" 264px; height: 21px">
                    </td>
                    <td style="height: 21px">
                    </td>
                </tr>
            </table>
       
        </div>
        </form>
    </body>
    </html>
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table cellpadding="1" cellspacing="1" style=" 523px; height: 199px; background-color: #cc6600">
                <tr>
                    <td align="right" style=" 132px">
                    </td>
                    <td align="center" style=" 264px">
                        User</td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Username</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextName" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Password</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextPwd" runat="server" BackColor="#FFC0C0" TextMode="Password"
                            Width="149px"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                    </td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextPwd2" runat="server" BackColor="#FFC0C0" TextMode="Password"
                            Width="149px"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 26px">
                        Quesqtion</td>
                    <td style=" 264px; height: 26px">
                        <asp:TextBox ID="TextQues" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 26px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 26px">
                        Answer</td>
                    <td style=" 264px; height: 26px">
                        <asp:TextBox ID="TextAnswer" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 26px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Email</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextEmail" runat="server" BackColor="#FFC0C0" Width="114px"></asp:TextBox>@<asp:DropDownList
                            ID="DropDownListemail" runat="server" BackColor="#FFC0C0" Width="99px">
                            <asp:ListItem Value="163.com"></asp:ListItem>
                            <asp:ListItem Value="yahoo.com.cn"></asp:ListItem>
                        </asp:DropDownList></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 13px">
                        Adress</td>
                    <td style=" 264px; height: 13px">
                        <asp:TextBox ID="TextAdress" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 13px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 8px">
                        Tel</td>
                    <td style=" 264px; height: 8px">
                        <asp:TextBox ID="TextTel" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 8px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 20px">
                        Phone</td>
                    <td style=" 264px; height: 20px">
                        <asp:TextBox ID="TextPhon" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td style="height: 20px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Company</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextCompany" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                        Country</td>
                    <td style=" 264px">
                        <asp:TextBox ID="TextCountry" runat="server" BackColor="#FFC0C0"></asp:TextBox></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="right" style=" 132px">
                    </td>
                    <td align="center" style=" 264px">
                        <asp:Button ID="Button1" runat="server" BackColor="#FFE0C0" OnClick="Button1_Click"
                            Text="OK" Width="51px" />
                        <input id="Reset1" style="background-color: #ffe0c0" type="reset" value="reset" /></td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="3" rowspan="2">
                        <asp:Label ID="Msg" runat="server"></asp:Label></td>
                </tr>
                <tr>
                </tr>
                <tr>
                    <td align="right" style=" 132px; height: 21px">
                    </td>
                    <td style=" 264px; height: 21px">
                    </td>
                    <td style="height: 21px">
                    </td>
                </tr>
            </table>
       
        </div>
        </form>
    </body>
    </html>

  • 相关阅读:
    网站添加手机短信功能
    FileWriter的正确使用,请及时关闭流
    myeclipse9.0没有提示
    Integer.getInteger,are you kinding me? 好吧, 我还是没怎么弄明白,求高人解答。。。
    构造方法充当临时对象&Calendar的使用
    关于Spring IOC的一点个人理解
    在JAVA中使用GUID
    动态生成table下的<tr>标签不显示
    MD5加密实例
    String,StringBuffer 和 StringBuilder 的区别
  • 原文地址:https://www.cnblogs.com/cestbon/p/ayuan.html
Copyright © 2020-2023  润新知