How to create customized cookies in .net program
I am gonna tell you that how you can create your own cookies in your program.
There is a namespace called System.Web, in which there is a class called HttpCookie, you have to include in your program.
The HttpCookie class gets and sets properties of specific cookies. The HttpCookieCollection class gives methods to store, retrieve, and handle multiple cookies.
— HttpCookie class
Now in the exact location, you have to create a object of that class to create your own cookie.
HttpCookie myCookie = new HttpCookie(“Cookiename”);
You have created a object of HttpCookie Class only and you create your own cookie, now you
can customized your own cookie like you can add key, backcolor, forecolor, font, size, username, lastlogin etc.
You can set the value of your cookie with this code:
Now what you think, you can add backcolor and forecolor with this code:
If you want to set your cookie’s font and size then with the help of this code, you can set
If you want to store something in your cookie, with the help of this code, you can
mycookie.Values.Add(“UserName”, Page.User.Identity.Name); //adding username
mycookie.Values.Add(“LastLogin”, DateTime.Now.ToString()); //adding lastlogin
* How to create customized cookies by HttpCookie