标签:
1 Cookie的设置和获取:
//默认浏览器关闭,cookie就消失,设置有效期,就到期后才消失
//cookie与浏览器相关,各种浏览器、同一浏览器窗口、小号模式,互不影响,各有一套cookie
//cookie中不能存太多数据、不能存铭感的不能修改password的数据
//cookie有可能提前消失,浏览器可以进行瘦身,或用户手动清楚cookie
public class cookie1 : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //设置cookie HttpCookie cookie = new HttpCookie("test"); //cookie.Value = "rupeng.com"; cookie.Value = context.Request.UserAgent; //设置有效期,如果没有,则浏览器关闭就消失 cookie.Expires = DateTime.Now.AddSeconds(10); context.Response.SetCookie(cookie); } public bool IsReusable { get { return false; } } }
public class cookie2 : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //获取cookie HttpCookie cookie = context.Request.Cookies["test"]; context.Response.Write(cookie==null?"没有这个cookie":cookie.Value); //修改cookie的值 //if(cookie!=null) //{ // cookie.Value = "Core就是必须学"; // context.Response.SetCookie(cookie); //} } public bool IsReusable { get { return false; } } }
标签:
原文地址:http://www.cnblogs.com/adolphyang/p/4778944.html