惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - kkk

无题 重出江湖! 技巧百问(10):UrlRewrite以及二级UrlRewrite 今天周末休息一天,发贴! 转贴:ASP.NET 2.0 中改进的缓存功能 一个多月来第一贴! 怀念一下《幽灵公主》 惊悚科幻 《灵幻夹克》 西安归来!(终于写完了) 支付宝Payto接口的c#.net实现 关于MD5码的一些自我总结 再总结一些技巧 超准的爱情测验! 转贴:Oracle(甲骨文)的CEO Larry.Ellison在耶鲁大学2000届毕业典礼上的演讲 转贴:出租车司机给微软高管上的MBA课程! 80个Gmail帐号,5个Live Messenger试用邀请,要的留言并注明是什么的邀请! 新年新贴! 回滚事务日志文件中的事务 转贴:ASP.NET中的UrlRewrite
关于asp.net c#中对cookie的操作 - kkk - 博客园
kkk · 2006-01-26 · via 博客园 - kkk

        今天有空就把操作cookie的写了,虽然很简单,不过免得到时候忘记了,之前就是忘记了还很实验了一番才弄出来,郁闷了。
        下面是写cookie

1 HttpCookie cookie = new HttpCookie("Info");//定义cookie对象以及名为Info的项
2 DateTime dt = DateTime.Now;//定义时间对象
3 TimeSpan ts=new TimeSpan(1,0,0,0);//cookie有效作用时间,具体查msdn
4 cookie.Expires = dt.Add(ts);//添加作用时间
5 cookie.Values.Add("user","cxbkkk");//增加属性
6 cookie.Values.Add("userid","1203");
7 Response.AppendCookie(cookie);//确定写入cookie中

        读取cookie

 1 if(Request.Cookies["Info"]!=null)
 2 {
 3     string temp=Convert.ToString(Request.Cookies["Info"].Values["user"])+"  "+Convert.ToString(Request.Cookies["Info"].Values["userid"]);
 4     //读全部就用Request.Cookies["Info"].Value)
 5     if(temp=="")
 6     {
 7         Response.Write("");
 8     }
 9     else
10         Response.Write(temp);
11 }
12 else
13 {
14     Response.Write("error");
15 }

        修改cookie

1 Response.Cookies["Info"]["user"= "2";
2 Response.Cookies["Info"].Expires = DateTime.Now.AddDays(1);

        删除cookie下的属性

1 HttpCookie acookie=Request.Cookies["Info"];
2 acookie.Values.Remove("userid");
3 acookie.Expires = DateTime.Now.AddDays(1);
4 Response.Cookies.Add(acookie);

        删除所有cookie,就是设置过期时间为现在就行了

1 int limit=Request.Cookies.Count - 1;
2 for(int i=0;i<limit;i++)
3 {
4     acookie = Request.Cookies(i)
5     acookie.Expires = DateTime.Now.AddDays(-1)
6     Response.Cookies.Add(acookie)
7 }

        这下不用到处找了