.net读取cookie中的值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.net读取cookie中的值相关的知识,希望对你有一定的参考价值。

登陆页面:Response.Cookies["id"].Value = loginnum.Text;
Response.Cookies["id"].Expires = DateTime.Now.AddDays(1);
转入的页面:
HttpCookie acookie = Request.Cookie("id");
Label1.Text = acookie.Value;

该怎么写呢 烦死了 搜索网上的方法都不行 不是不包含cookie的定义就是未引用到对象 帮帮忙 谢谢了
lipt1845你好 读取出来的还是空 怎么弄啊

你好:
写入方法:
HttpCookie cookie = new HttpCookie("id");
cookie.Value=cookieValue;
cookie.Expires = DateTime.Now+new TimeSpan(0,1,0,0));
Response.Cookies.Add(cookie);
读取方法:
HttpCookie cookie = Request.Cookies["id"];
if(null == cookie)

Label1.Text = "";

else

Label1.Text = cookie.Value;
参考技术A if (Request.Cookies["id"]!=null)
Label1.Text=Request.Cookies["id"].Value;

以上是关于.net读取cookie中的值的主要内容,如果未能解决你的问题,请参考以下文章

如何在JSON.NET中读取json对象值中的long值数组

如何为 ASP.net/C# 应用程序配置文件值中的值添加与号

如何读取redis中的key值中的结果

如何读取redis中的key值中的结果

在值中搜索字符串并在 VB.NET 中的 LINQ to XML 中获取属性值

c#如何读取json中的值