用session 相对cookies而言安全点,但是回存在失效为题
这里介绍下cookies的简单用法
//声明、写入cookies
HttpCookie cookie = new HttpCookie("UserName");
cookie.Value = name;
if (Convert.ToInt32(this.ddlDate.SelectedValue) <31)
{
cookie.Expires = DateTime.Today.AddDays(Convert.ToInt32(this.ddlDate.SelectedValue));
}
else
{
cookie.Expires = DateTime.Today.AddHours(Convert.ToInt32(this.ddlDate.SelectedValue));
}
//这句不能丢
Response.Cookies.Add(cookie);
读取cookies
if (Request.Cookies["UserName"]!=null)
{
this.lblWelcome.Text = Request.Cookies["UserName"].Value + ",欢迎来到尊贵商城!";
this.pnlWelcome.Visible = true;
this.pnlLogout.Visible = true;
this.pnlLogin.Visible = false;
}