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

推荐订阅源

C
CERT Recently Published Vulnerability Notes
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Tor Project blog
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Latest news
Latest news
L
LINUX DO - 热门话题
罗磊的独立博客
T
Tenable Blog
The Hacker News
The Hacker News
美团技术团队
N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
博客园 - 司徒正美
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
云风的 BLOG
云风的 BLOG
S
Secure Thoughts
Cloudbric
Cloudbric
S
Security @ Cisco Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
U
Unit 42
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
爱范儿
爱范儿
博客园 - 【当耐特】
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
P
Palo Alto Networks Blog
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
F
Full Disclosure
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security Affairs
Project Zero
Project Zero

博客园 - sh37

Newtonsoft中的几个妙用 Mvc中ViewData与TempData的区别 Silverlight中利用ListBox特性实现单选按钮组RadioButtonList和复选按钮组CheckBoxList的功能 SilverLight中Page也可使用泛型基类 C# 利用net 命令获取域用户列表 - sh37 利用MessageQueue收发消息 - sh37 - 博客园 C# xmlhttp - sh37 - 博客园 使用ASP获得AD帐号 “域\用户名” - sh37 - 博客园 使用ASP.NET获得AD帐号 - sh37 - 博客园 根據xml文檔數據 給DataTable增加行 JS获取剪贴板内容的代码 - sh37 - 博客园 分页时使当前页码变色 C#生成缩略图 自動生成帶文字的圖片 常用pl/sql vb.net後台抓取網頁內容 ServerVariables集合内容列表 如何动态创建一个按纽 并给这个按纽绑上一个Onclick事件 17种常用正则表达式
cookie操作 - sh37 - 博客园
sh37 · 2007-09-27 · via 博客园 - sh37

今天有空就把操作cookie的写了,虽然很简单,不过免得到时候忘记了。
        下面是写cookie
 HttpCookie cookie = new HttpCookie("Info");//定义cookie对象以及名为Info的项
 DateTime dt = DateTime.Now;//定义时间对象
 TimeSpan ts=new TimeSpan(1,0,0,0);//cookie有效作用时间,具体查msdn
 cookie.Expires = dt.Add(ts);//添加作用时间
 cookie.Values.Add("user","cxbkkk");//增加属性
 cookie.Values.Add("userid","1203");
 Response.AppendCookie(cookie);//确定写入cookie中        读取cookie
  if(Request.Cookies["Info"]!=null)
  {
      string temp=Convert.ToString(Request.Cookies["Info"].Values["user"])+"  "+Convert.ToString(Request.Cookies["Info"].Values["userid"]);
     //读全部就用Request.Cookies["Info"].Value)
     if(temp=="")
      {
          Response.Write("空");
      }
      else
         Response.Write(temp);
 }
 else
 {
     Response.Write("error");
 }       // 改cookie
 Response.Cookies["Info"]["user"] = "2";
 Response.Cookies["Info"].Expires = DateTime.Now.AddDays(1);        //删除cookie下的属性
 HttpCookie acookie=Request.Cookies["Info"];
 acookie.Values.Remove("userid");
 acookie.Expires = DateTime.Now.AddDays(1);
 Response.Cookies.Add(acookie);        //删除所有cookie,就是设置过期时间为现在就行了
 int limit=Request.Cookies.Count - 1;
 for(int i=0;i<limit;i++)
 {
     acookie = Request.Cookies(i)
     acookie.Expires = DateTime.Now.AddDays(-1)
     Response.Cookies.Add(acookie)
 }  

posted on 2007-09-27 11:02  sh37  阅读(196)  评论()    收藏  举报