Cookies are widely used in majority of web applications. They are used in login forms, shopping cart, or simply to track users. This example demonstrates how to write, read values using a cookie using C#.
//To Write to a cookie
HttpCookie userCookie;
UserName="admin";
userCookie = new HttpCookie("UserName") ;
cookie.Values.Add(UserName, UserName) ;
Response.Cookies.Add(userCookie);
// To read from a cookie
HttpCookie userCookie;
userCookie = Request.Cookies["UserName"];
String UserName = userCookie.Value;
That's it!



