[C #] Simple Helper encapsulation,
1 using System; 2 using System. web; 3 4 namespace ConsoleApplication5 5 {6 /// <summary> 7 // Cookie assistant 8 /// </summary> 9 public sealed class CookieHelper10 {11 /// <summary> 12 // Add a Cookie13 /// </summary> 14 /// <param name = "name"> name </param> 15 /// <param name =" value "> value </param> 16 public static void Add (string name, string value) 17 {18 var cookie = new HttpCookie (name, value); 19 20 HttpContext. Current. response. cookies. add (cookie ); 21} 22 23 // <summary> 24 // Add a Cookie25 // </summary> 26 // <param name = "name"> name </param> 27 /// <param name = "value"> value </param> 28 /// <param name = "expires"> expiration date and time </param> 29 public static void Add (string name, string value, DateTime expires) 30 {31 var cookie = new HttpCookie (name, value) 32 {33 Expires = expires34}; 35 36 HttpContext. current. response. cookies. A Dd (cookie ); 37} 38 39 // <summary> 40 // obtain the Cookie value 41 // </summary> 42 // <param name = "name"> name </ param> 43 // <returns> </returns> 44 public static string Get (string name) 45 {46 var cookie = HttpContext. current. request. cookies [name]; 47 48 return cookie = null? String. Empty: cookie. Value; 49} 50} 51}