Posted By

krisdb on 06/04/08


Tagged

c-sharp


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


cookies


 / Published in: C#
 

  1. public class Cookie
  2. {
  3. public Cookie()
  4. {
  5.  
  6. }
  7.  
  8. public void Set(string name, string value, DateTime expires)
  9. {
  10. HttpCookie cookie = new HttpCookie(name);
  11. cookie.Value = value;
  12. cookie.Expires = expires;
  13. HttpContext.Current.Response.Cookies.Add(cookie);
  14. }
  15.  
  16. public string Get(string name)
  17. {
  18. HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
  19.  
  20. if (cookie != null)
  21. return cookie.Value;
  22. else
  23. return String.Empty;
  24. }
  25.  
  26. public void Delete(string name)
  27. {
  28. HttpCookie cookie = new HttpCookie(name);
  29. cookie.Expires = DateTime.Now.AddDays(-1d);
  30. HttpContext.Current.Response.Cookies.Add(cookie);
  31. }
  32. }

Report this snippet  

You need to login to post a comment.