当前位置:编程学习 > C#/ASP.NET >>

已经取得COOKIE,如何正确使用它?

通过webbrowser已经取得登录后的COOKIE,我把COOKIE加到HEADER里,访问登录后才能访问的页面,但是访问失败。请问究竟应该如何使用COOKIE? --------------------编程问答-------------------- 楼主想搞非法cookie? --------------------编程问答-------------------- asp.net cookies的使用方法
Response.Cookie("username").value="aa" 写入 
username=Request.Cookies("username").value 读取 
最好用SESSION比较方便 
session("username")="aa" 写入 
username=session("username") 读取


C# : 

方法1: 
Response.Cookies["username"].Value="gjy"; 
Response.Cookies["username"].Expires=DateTime.Now.AddDays(1); 

方法2: 
System.Web.HttpCookie newcookie=new HttpCookie("username"); 
newcookie.Value="gjy"; 
newcookie.Expires=DateTime.Now.AddDays(1); 
Response.AppendCookie(newcookie); 


创建带有子键的cookies: 
System.Web.HttpCookie newcookie=new HttpCookie("user"); 
newcookie.Values["username"]="gjy"; 
newcookie.Values["password"]="111"; 
newcookie.Expires=DateTime.Now.AddDays(1); 
Response.AppendCookie(newcookie); 



cookies的读取: 

无子键读取: 
if(Request.Cookies["username"]!=null) 

Response.Write(Server.HtmlEncode(Request.Cookies["username"].Value)); 


有子键读取: 
if(Request.Cookies["user"]!=null) 

Response.Write(Server.HtmlEncode(Request.Cookies["user"]["username"].Value)); 


--------------------编程问答--------------------
引用 2 楼 gefangliang 的回复:
asp.net cookies的使用方法
Response.Cookie("username").value="aa" 写入 
username=Request.Cookies("username").value 读取 
最好用SESSION比较方便 
session("username")="aa" 写入 
username=session("username") 读取


C……

够详细了 --------------------编程问答--------------------
引用 2 楼 gefangliang 的回复:
asp.net cookies的使用方法
Response.Cookie("username").value="aa" 写入 
username=Request.Cookies("username").value 读取 
最好用SESSION比较方便 
session("username")="aa" 写入 
username=session("username") 读取


C#……

好详细,顶一个! --------------------编程问答-------------------- 顶一个 --------------------编程问答--------------------
引用 2 楼 gefangliang 的回复:
asp.net cookies的使用方法
Response.Cookie("username").value="aa" 写入 
username=Request.Cookies("username").value 读取 
最好用SESSION比较方便 
session("username")="aa" 写入 
username=session("username") 读取


C#……

不要误导
方法:首先判断是POST还是GEI
然后用httpWebRequest,httpWebResponse类发HTTP协议
--------------------编程问答--------------------
引用 2 楼 gefangliang 的回复:
asp.net cookies的使用方法
Response.Cookie("username").value="aa" 写入 
username=Request.Cookies("username").value 读取 
最好用SESSION比较方便 
session("username")="aa" 写入 
username=session("username") 读取


C……


百度一下 你都能 知道的  还提问
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,