//创建一个新的Cookie
HttpCookie newCookie = new HttpCookie("User");
//往Cookie里面添加值,均为键/值对。Cookie可以根据关键字寻找到相应的值
newCookie.Values.Add("Name","Hui Yongliang"); newCookie.Values.Add("Pwd","123456");newCookie.Expires = DateTime.Now.AddDays(14);
//Cookie的设置页面要用Response Response.AppendCookie(newCookie);
//设置Session的值
Session["Name"] = "Hui Yongliang";
Session["Pwd"] = "123456";//Home页面前台代码
<asp:Button ID="btnReset" runat="server" Text="注销" οnclick="btnReset_Click"
Visible="False" />
//获得login页面的Cookie值 要用Request
HttpCookie newCookie = Request.Cookies["User"]; if (newCookie != null) { Response.Write("欢迎" + newCookie.Values["Name"] + "来到该网站," + "你的密码是:" + newCookie.Values["Pwd"]); }//获得login页面的session值
if (Session["Name"] != null) { Response.Write("欢迎" + Session["Name"] + "来到该网站," + "你的密码是:" + Session["Pwd"]); btnReset.Visible = true; } else { Response.Write("您还没有登陆!<a href='Login.aspx'>返回登陆</a>"); } }