最新下载
热门教程
- 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);
相关文章
- 《交错战线》好友拜访有什么好的方法可用 06-16
- 《无期迷途》降临烙印深度介绍 06-16
- 最火2025币圈十大加密货币交易所榜单-最好用比特币交易app币安推荐 06-16
- SNORT币怎么交易-2025币安交易所新手全攻略 06-16
- 《大侠立志传》韩红玉结缘有什么 06-16
- Metaplanet最新购入1,112枚比特币后总持仓突破1万枚大关 06-16