对于WEB的开发,会用Cooikes传值,这里介绍下Cooikes的常用的一些方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
public static class Cooikes { /// <summary> /// 写入Cookie /// </summary> public static void WriteCooike(string name ,string value) { System.Web.HttpContext.Current.Response.Cookies[name].Value = value; System.Web.HttpContext.Current.Response.Cookies[name].Expires = DateTime.Now.AddYears(50); } /// <summary> /// 读取Cookie /// </summary> /// <param name="name"></param> /// <returns></returns> public static string ReadCookie(string name) { string value = ""; if (System.Web.HttpContext.Current.Request.Cookies[name] != null) { value = System.Web.HttpContext.Current.Request.Cookies[name].Value; } return value; } /// <summary> /// 删除Cookie /// </summary> /// <param name="name">Cookie的名称</param> public static void DeteleCookie(string name ) { System.Web.HttpContext.Current.Response.Cookies[name].Expires = DateTime.Now.AddDays(-1); } } |