Cookie : Cookie is a small key value pair which is used to store the small piece of user information.
2 types are cookies are available in asp.net.
Session Cookie and persistent cookie
Session Cookie: These are stored in in-memory during the client browser session when the browser is closed the session cookies are lost.
Ex
HttpCookie sCookie=New HttpCookie("uname","Anji");
Response.cookies.add(sCookie);
//Code to read the cookie
string name= Request.cookies["uname"].value;
Persistent cookies are same as session cookies except that persistent cookies have an expiration date.These are generally used to store info that identifies a returning user to web site like user name or logid.
Creation of persistent cookies
HttpCookie pCookie=New HttpCookie("uname","Anji");
pCookie.Expires=DateTime.Now.AddDays(10);
Response.cookies.add(pCookie);
Cookie Dictionary : It is a single cookie object which can store multiple pieces of information You can use values properties to access and assign new values to cookiedictionary.
Advantages:
Easy to implement.
Does not require server resources.
Dis Advantages:
User can delete the cookie.
Browser can refuse the cookies.
Cookies are not secure.
Any one can view your cookie data once he logged in into your machine.
2 types are cookies are available in asp.net.
Session Cookie and persistent cookie
Session Cookie: These are stored in in-memory during the client browser session when the browser is closed the session cookies are lost.
Ex
HttpCookie sCookie=New HttpCookie("uname","Anji");
Response.cookies.add(sCookie);
//Code to read the cookie
string name= Request.cookies["uname"].value;
Persistent cookies are same as session cookies except that persistent cookies have an expiration date.These are generally used to store info that identifies a returning user to web site like user name or logid.
Creation of persistent cookies
HttpCookie pCookie=New HttpCookie("uname","Anji");
pCookie.Expires=DateTime.Now.AddDays(10);
Response.cookies.add(pCookie);
Cookie Dictionary : It is a single cookie object which can store multiple pieces of information You can use values properties to access and assign new values to cookiedictionary.
Advantages:
Easy to implement.
Does not require server resources.
Dis Advantages:
User can delete the cookie.
Browser can refuse the cookies.
Cookies are not secure.
Any one can view your cookie data once he logged in into your machine.
It 's excellent posting
ReplyDeleteDot Net Online Training Hyderabad