Friday, February 22, 2013

C# cookies

Create a cookie:

HttpCookie myCookie = new HttpCookie("MyCookie");
myCookie["Content"] = "Hello World";
myCookie.Path = "/Support";
myCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);

 
 

Go fishing for it later on:

HttpCookie myCookie = new HttpCookie("MyCookie");
myCookie = Request.Cookies["MyCookie"];
if (myCookie != null)
{
   Label1.Text = myCookie["Content"];
}

No comments:

Post a Comment