Loading

Cookies in asp.net

Submitted by: 


Cookies are one of the way to store data during the time when web server and browser are not
connected. common use of cookies is to remember users between visits.Cookies is a small text file
sent by web server and saved by web browser on client machine

Creating cookies in asp.net

  1. using system
  2.  
  3. //saving cookie
  4. Response.Cookies["Cookiename"].Value="biscuit";
  5.  
  6. //when cookiesz expires
  7. Response.Cookies["Cookiename"].Expires = DateTime.Now.AddDays(1);

Reading cookies in asp.net

  1. string CookienameValue;
  2.  
  3. // if cookie not exists
  4. if(Request.Cookies["Cookiename"] != null)
  5. CookienameValue = Request.Cookies["Cookiename"].Value;
  6.  
  7. Deleting Cookies in asp.net
  8.  
  9. // First check if cookie exists
  10. if (Request.Cookies["Cookiename"] != null)
  11. {
  12. // Set its expiration time somewhere in the past
  13. Response.Cookies["Cookiename"].Expires = DateTime.Now.AddDays(-1);
  14. }

About the author:

Planet Source Code is a place for all developer providing free source codes, articles, complete projects,complete application in PHP, C/C++, Javascript, Visual Basic, Cobol, Pascal, ASP/VBScript, AJAX, SQL, Perl, Python, Ruby, Mobile Development




Add new comment