之前登陆学校的教务系统或者考试系统,进入界面都会有“欢迎***登陆本系统”。当时就认为挺高级。如今轮
到自己做这个样例。突然感觉是so easy。
仅仅需简单几步,就可能够搞定。
编写server代码例如以下:
protected void Page_Load(object sender, EventArgs e) { string userName = Request.Form["userName"].ToString(); //获取username string userPwd = Request.Form.Get("userPwd").ToString(); //获取password SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=***"); //连接数据库 con.Open(); SqlCommand cmd = new SqlCommand("select count(*) from login where userName='"+userName+"' and userPwd='"+userPwd+"'" ,con); int count = Convert.ToInt32(cmd.ExecuteScalar()); if (count>0) { Response.Redirect("main.aspx"); //验证成功 } else { Response.Redirect("loginFail.html"); //验证失败 } }
转载于:https://www.cnblogs.com/bhlsheji/p/5402256.html