Exemplo n.º 1
0
        //登录按钮
        protected void ButtonLogin_Click(object sender, EventArgs e)
        {
            if (this.username.Text.Trim() == "" || this.password.Text.Trim() == "")
            {
                Response.Write("<script>alert('用户名和密码不能为空!');window.history.go(-1)</script>");
                return;
            }
            if (txtAdminCode.Text != labCode.Text)
            {
                Response.Write("<script>alert('验证码不匹配,请重新填写!');window.history.go(-1)</script>");
                txtAdminCode.Text = "";
                return;
            }
            userinfo user = new userinfo();

            if (user.validUser(this.username.Text.Trim().ToString(), this.password.Text.Trim().ToString()))
            {
                Session["userName"] = this.username.Text.Trim().ToString();
                if (CheckBox1.Checked)    //是否记住用户名
                {
                    Response.Cookies["username"].Value   = username.Text;
                    Response.Cookies["username"].Expires = DateTime.Now.AddDays(1);
                }
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('登录成功!');</script>");
                Server.Transfer("index.aspx");
            }
            else
            {
                Session["userName"] = "";
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('登录失败,无此用户名或密码不正确!');window.history.go(-1)</script>");
            }
        }