登录页面botton代码如下:
libraryDataContext xx = new libraryDataContext();
string a = this.DropDownList2.SelectedValue;
var q = from n in xx.VipReader
where n.姓名 == TextBox2.Text && n.密码 == TextBox3.Text
select n;
if (q.Count() == 1)
{
Response.Write("<script>alert('登录成功!');location='用户/用户信息.aspx'</script>");
HttpCookie cookie = new HttpCookie("name");
//写出name的内容
cookie.Value = TextBox3.Text;
//Expires是指过期时间=DateTime.Now.AddDays(1)是指它的过期的日期为当前日期再加上一天
cookie.Expires = DateTime.Now.AddDays(1);
//这段代码才真正的写到客户端当中
Response.Cookies.Add(cookie);
}
else
{
Response.Write("<script>alert('登录失败!用户名或密码错误!');location='首页.aspx'</script>");
}
跳转至用户信息页面后代码如下:
public partial class 用户信息 : System.Web.UI.Page
{
string ConString = ConfigurationManager.ConnectionStrings["library"].ConnectionString.ToString();
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = Request.Cookies["name"].Value;
SqlConnection con = new SqlConnection(ConString);
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select 姓名 from VipReader where 密码 = 'TextBox1.Text'";
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
string a = reader.GetString(0);
con.Close();
Label10.Text = a;
}
}
}
但是