寫cookie
HttpCookie cookie = new HttpCookie(“Info”);//定義cookie對象以及名為Info的項
DateTime dt = DateTime.Now;//定義時間對象
TimeSpan ts=new TimeSpan(1,0,0,0);//cookie有效作用時間,具體查msdn
cookie.Expires = dt.Add(ts);//添加作用時間
cookie.Values.Add(“user”,”cxbkkk”);//增加屬性
cookie.Values.Add(“userid”,”1203″);
Response.AppendCookie(cookie);//確定寫入cookie中
讀取cookie
if(Request.Cookies[“Info”]!=null)
{
string temp=Convert.ToString(Request.Cookies[“Info”].Values[“user”])+” “+Convert.ToString(Request.Cookies[“Info”].Values[“userid”]);
//讀全部就用Request.Cookies[“Info”].Value)
if(temp==””)
{
Response.Write(“空”);
}
else
Response.Write(temp);
}
else
{
Response.Write(“error”);
}