龙亿

------ 细细口味人生中的每一杯苦咖啡.

导航

HttpCookie类

Posted on 2008-11-05 23:22  龙亿  阅读(1143)  评论(1编辑  收藏  举报

HttpCookie类,语法定义如下:

public sealed class HttpCookie

"sealed" 关键字表示此类是密封类,不能被继承;

二种构造函数;一种不能为键赋值,另一种是指定键/值

public HttpCookie (string name)

public HttpCookie(string name,string value)

事例:

Request.Cookie.Clear()

HttpCookie myname = new HttpCookie("UserInfo");

myname["name"]=TextBox1.text;

myname["passWord"]=textBox2.text;

myname.Expires=DateTime.Now.AddHours(1);

Response.Cookies.Add(myname);

 

 

加载页面时代码:

if (Request.Cookie["UserInfo"]!=Null)

{

     textBox1.text=Request.Cookie["UserInfo"]["name"].Tostring();

     textBox2.text=Request.Cookie["UserInfo"]["passWord"].Tostring();

}