zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    Android使用LocalSocket抓取数据
    求一个数组的最长递减子序列 比如{9,4,3,2,5,4,3,2}的最长递减子序列为{9,5,4,3,2}
    链表A和B的有序合并,合并过程不产生新的节点,合并后B消失
    Android中intent如何传递自定义数据类型
    字符串的排列组合问题
    android.net.LocalSocket
    [转]OWC生成柱图,线图,饼图
    利用C#对远程服务进行操作
    域备份&域还原
    ActiveReports for .NET 简单使用
  • 原文地址:https://www.cnblogs.com/cestbon/p/ayuan.html
Copyright © 2011-2022 走看看