Cookies are used to store the credentials and providing and remembering it whenever needed.
Cookies are on both side client side as well as on server side.
Types of Cookies:
Persistent
Non-persistent
Persistent cookies exists till their life time expires
Non-persistent cookies dont have expiry time associated with it . It expires as soon as the browser or window is closed
Creating Cookies
//Creting a Cookie Object
HttpCookie userInfoCookies = new HttpCookie("UserInfo");
//Setting values inside it
userInfoCookies["UserName"] = "Abhijit";
userInfoCookies["UserColor"] = "Red";
userInfoCookies["Expire"] = "5 Days";
//Adding Expire Time of cookies
userInfoCookies.Expires = DateTime.Now.AddDays(5);
//Adding cookies to current web response
Response.Cookies.Add(userInfoCookies);
0 Comment(s)