|
index.aspx.cs
private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(Session["UserName"]==null) { //如果用户未登陆 T2.Visible =false;//隐藏表格二 } else//如果登陆 { T1.Visible =false;//隐藏表格一 Label1.Text =Session["UserName"].ToString();//显示用户名 } }
|
|
index.aspx.cs登陆部分
string UserName=Request.Form["name"]; string upassword=Request.Form["password"]; SqlConnection myConn=DBCONN.CreateCon(); myConn.Open(); string strSql = "select * from user01 where name='"+UserName+"' and password='"+upassword+"'"; SqlCommand cmd= new SqlCommand(strSql,myConn); SqlDataReader myrs = cmd.ExecuteReader(); if (myrs.Read()) { Session["UserName"]=name.Text ;//生成用户的Session Response.Redirect ("index.aspx");//转向首页,起刷新作用 } else { myConn.Close(); Response.Write("对不起,该会员名不存在或密码错误!"); //Response.Redirect ("default.aspx");//转向首页,起刷新作用 } myrs.Close ();//一切读取行为结束后,一定要关闭阅读器 myConn.Close();
|
|
index.aspx.cs注销部分
private void Button2_Click(object sender, System.EventArgs e) { Session["UserName"]=null; Response.Redirect("index.aspx"); }
|
看不懂留下邮箱,我给你发一份..
发表于 @ 2006年06月18日 01:10:00|评论(loading...)|编辑