protected void Page_Load(object sender, EventArgs e)
{
HttpCookie MyCookie = Request.Cookies["User_location"];
if (MyCookie == null || MyCookie.Value.Length <= 0)
{
string Location_txt = "王先生" + "|" + DateTime.Now.ToString();
MyCookie= new HttpCookie("User_location", Location_txt);
MyCookie.Expires.AddYears(100);
Response.Cookies.Add(MyCookie);
}
else
{
Response.Write("現在登錄時間:" + DateTime.Now.ToString() + "<br/>");
string[] Loca_txt = MyCookie.Value.Split(new char[] { '|' });
Response.Write("用戶名:" + Loca_txt[0].ToString() + "<br/>");
Response.Write("上次登錄時間:" + Loca_txt[1].ToString() + "<br/>");
MyCookie.Value = Loca_txt[0].ToString() + "|" + DateTime.Now.ToString();
Response.Cookies.Set(MyCookie);
//Response.AppendCookie(MyCookie);同下
string[] keysstr = Response.Cookies.AllKeys;
Response.Write(keysstr[0]);
}
}
cookie 的書寫
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.