Cookie中多个变量的设置.
设置Cookie:
HttpCookie xpcookie=new HttpCookie("param");
xpcookie.Values.Add("YYYY",TempYear);
xpcookie.Values.Add("MM",TempMonth);
xpcookie.Values.Add("Selflag",TempFlag);
xpcookie.Values.Add("Selvalue",TempValue);
Response.AppendCookie(xpcookie);
接到Cookie:
//得到Cookie值
HttpCookie getCookie=Request.Cookies["param"];
getyear=getCookie.Values["YYYY"].ToString();
getmonth=getCookie.Values["MM"].ToString();
flagSel=getCookie.Values["Selflag"].ToString();
string valueSel1=getCookie.Values["Selvalue"].ToString();
如果是单个变量:
设置:
HttpCookie curCookie=new HttpCookie("pass");
curCookie.Value="yes";
Response.AppendCookie(curCookie);
接到:
HttpCookie curCookie=Request.Cookies["pass"];
if(curCookie==null)
{
……
}
else
{
string curValue=curCookie.Value.Trim();
……
}
上面的Cookie都没有设置时间过期的值,这样就是IE关掉cookie就自动删除
如果要设置过期时间的话,可以在此设置时间: curCookie.Expires=DateTime.now.Addday(1);本文地址:http://com.8s8s.com/it/it7934.htm