最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何保存一个字符串Cookie,在其它WebForm中可以访问到?
时间:2008-01-18 编辑:简简单单 来源:一聚教程网
设置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);
-
上一个: 刷新帧,文件名fresh.asp
-
下一个: ASP中得到用户的真实IP地址
相关文章
- VBS 批量Ping的项目讲解 09-19
- 如何封装一个Ajax函数介绍 09-16
- ASP实现加法验证码方法 09-16
- ASP错误捕获的几种常规处理方法介绍 09-16
- ajax实现城市三级联动的代码介绍 09-16
- asp中获取日期为星期几的技巧 09-14