http://www.blogjava.net/ebecket 返还网
随笔-140  评论-11  文章-131  trackbacks-0
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));
posted on 2009-10-16 14:16 becket_zheng 阅读(172) 评论(0)  编辑  收藏 所属分类: web前端开发

只有注册用户登录后才能发表评论。


网站导航: