简单的asp.net模拟邮箱系统基础实现(二 (2)具体版块功能的实现及关键代码之登陆页面)

    xiaoxiao2021-03-25  147

    登陆界面:

     

    前台代码比较简单就不贴了

     

    c#

     

    要要引入

    using System.Data.SqlClient;

    using System.Data;

     

    namespace email

    {

        public partial class LoginPage : System.Web.UI.Page

        {

            protected void Page_Load(object sender,EventArgs e)

            {

     

            }

    //登陆  获取控件中的值 去数据库查询是否存在来完成用户名和密码的验证

            protected void login_Click(object sender,EventArgs e)

            {

                int t;

                String str = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\asus\Documents\Visual Studio 2015\Projects\email\email\App_Data\DB.mdf; Integrated Security = True";

                SqlConnection con = new SqlConnection(str);

                try

                {

                    con.Open();

                    SqlCommand cmd = new SqlCommand("select count(*) from userinfor  where USERID=@user and PASS=@pass", con);

                    cmd.Parameters.Add("@user",SqlDbType.NVarChar);

                    cmd.Parameters.Add("@pass",SqlDbType.NVarChar);

                    cmd.Parameters[0].Value = username.Text;

                    cmd.Parameters[1].Value = password.Text;

     

                    t = (int)cmd.ExecuteScalar();

                    if (t > 0)

                    {

                        Session["userid"] = username.Text;

                        Response.Redirect("~/SendPage.aspx");

                    }

                    else

                    {

                        inf.Text = "用户名或密码错误";

                    }

     

                }

                catch

                {

                    login.Text = "连接失败";

                }

                finally

                {

                    con.Close();

                }

            }

        }

    }

    转载请注明原文地址: https://ju.6miu.com/read-1370.html

    最新回复(0)