最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何保存一个字符串Cookie,在其它WebForm中可以访问到?
时间:2022-07-02 23:32:04 编辑:袖梨 来源:一聚教程网
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);
设置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);
相关文章
- 密室逃脱模拟器2如何获得奖杯成就 04-17
- 歧路旅人0海德内如何加入 04-17
- 风启之旅前期火药获取位置介绍说明 04-17
- 一耽漫画下载官方正版安装包-一耽漫画app免费下载最新版本在线观看 04-17
- 《Garden in》白金撒花成就解锁指南 04-17
- 前往中世纪房间是什么 04-17