Cookies in asp.net
Submitted by planetsourcecode on Saturday, June 6, 2009 - 20:48.
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
using system
//saving cookie
Response.Cookies["Cookiename"].Value="biscuit";
//when cookiesz expires
Response.Cookies["Cookiename"].Expires = DateTime.Now.AddDays(1);
Reading cookies in asp.net
string CookienameValue;
// if cookie not exists
if(Request.Cookies["Cookiename"] != null)
CookienameValue = Request.Cookies["Cookiename"].Value;
Deleting Cookies in asp.net
// First check if cookie exists
if (Request.Cookies["Cookiename"] != null)
{
// Set its expiration time somewhere in the past
Response.Cookies["Cookiename"].Expires = DateTime.Now.AddDays(-1);
}
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
- 16 views