We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

krisdb on 06/04/08


Tagged

c-sharp


Versions (?)


cookies


Published in: C# 


  1. public static void Cookie_Set(string strCookieName, string strCookieValue, DateTime dtExpires)
  2. {
  3. HttpCookie cookie = new HttpCookie(strCookieName);
  4. cookie.Value = strCookieValue;
  5. cookie.Expires = dtExpires;
  6. HttpContext.Current.Response.Cookies.Add(cookie);
  7. }
  8.  
  9. public static string Cookie_Get(string strCookieName)
  10. {
  11. HttpCookie cookie = HttpContext.Current.Request.Cookies[strCookieName];
  12.  
  13. if (cookie != null)
  14. return cookie.Value;
  15. else
  16. return "";
  17. }
  18.  
  19. Delete cookie:
  20. HttpCookie myCookie = new HttpCookie("[cookie name]");
  21. myCookie.Expires = DateTime.Now.AddDays(-1d);
  22. Response.Cookies.Add(myCookie);

Report this snippet 

You need to login to post a comment.