Persistent and Non Persistent cookies

Posted by Rajasekhar0544 under ASP.NET on 12/11/2012 | Points: 10 | Views : 17319 | Status : [Member] | Replies : 2
Hi All,

Could you please tell me the persistent and non persistent cookies with an example.
Provide the default expiration time of Non persistent cookie.
I have found many forums explaining this but im unable to figure it out. so kindly help me.

Thanks&Regards,
RajSekhar.




Responses

Posted by: Pavanandey on: 12/11/2012 [Member] Bronze | Points: 25

Up
0
Down
Persistent cookies - These remain on your hard drive until you erase them or they expire.
Non-Persistent cookies - Are stored in RAM on the client and are destroyed when the browser is closed.

Thanks
Pavan Kumar
Mark Answer if this fits the need

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 12/11/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Persistent cookies:- which are stored in the client hard-drive until they expire. Persistent cookies should be set with an expiration dates. Sometimes cookies stays until the user deletes the cookies.

//Creting a Cookie Object
HttpCookie _EmpInfoCookies = new HttpCookie("EmpInfo");
//Setting values inside it
_EmpInfoCookies["UserName"] = "Ajit";
_EmpInfoCookies["UserColor"] = "Green";
//Adding Expire Time of cookies
_EmpInfoCookies.Expires = DateTime.Now.AddDays(1);
//Adding cookies to current web response
Response.Cookies.Add(_EmpInfoCookies);

Non-persistent Cookies:- These can be called temporary Cookies. If there is no expiration time defined, then the cookie is stored in the browser memory.

//Creting a Cookie Object
HttpCookie _EmpInfoCookies = new HttpCookie("EmpInfo");
//Setting values inside it
_EmpInfoCookies["UserName"] = "Ajit";
_EmpInfoCookies["UserColor"] = "Green";
//Adding cookies to current web response
Response.Cookies.Add(_EmpInfoCookies);


Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response