Docstoc

COOKIES CODE

Document Sample
COOKIES CODE Powered By Docstoc
					//COOKIES CODE

Steps:

//check if browser accepts cookies.

//if the cookie does not exist..

//Create the cookie.

//Set the expiration to tomorrow

//Add to cookies collection.

//Display message

//else

//Get the Cookie

//Display a message showing time of last visit.

//Update the cookie on the client.



---------

Page_Load

-----------

//check if browser accepts cookies.

if(Request.Browser.Cookies)

{

//if the cookie does not exist..

if(Request.Cookies["LastVisit"]== null)

{

//Create the cookie.

HttpCookie cookLastVisit =new HttpCookie("LastVisit",DateTime.Now.ToString());



//Set the expiration to tomorrow

cookLastVisit.Expires=DateTime.Now.AddDays(1);
//Add to cookies collection.

Response.Cookies.Add(cookLastVisit);

//Display message

label1.Text="This is your first visit.";



}



else

{

//Get the Cookie

HttpCookie cookLastVisit = Request.Cookie["LastVisit"];

//Display a message showing time of last visit.

label1.Text="You last visited this page : " + cookLastVisit.Value;

//Update the cookie on the client.

Response.Cookies["LastVisit"].Value = DateTime.Now.ToString();

Response.Cookies[""].Expires=DateTime.Now.AddDays(1);

}

}

else

{

label1.Text="Your browser does not accept cookies.";

}

				
DOCUMENT INFO
Shared By:
Tags: COOKIES, CODE
Stats:
views:0
posted:2/23/2012
language:
pages:2
Description: COOKIES CODE