Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to use cookies in asp.net program ..can any body tell me how to use ?
Posted

Also have a look at this very good article: Beginner's Guide To ASP.NET Cookies[^]
 
Share this answer
 
Comments
thatraja 23-May-11 14:44pm    
Better link
Sandeep Mewara 23-May-11 15:06pm    
Yup! :)
Following is example for adding a cooking and fetching value from an existing cookie

Creating a new cookie
C#
HttpCookie Testcookie = new HttpCookie("CookieName");
//Set cookies value
Testcookie.Value = "CookieValue";
//Set the cookie to expire in 5 minutes
Testcookie.Expires = DateTime.Now.AddMinutes(5);
//Add the cookie in response
Response.Cookies.Add(Testcookie);

Retrive value of an existing cookie
C#
HttpCookie TestCookie = Request.Cookies["CookieName"];
if (TestCookie!=null)
{
    Response.Write("Cookie values is "+TestCookie.Value.ToString());
}

Hope this will be helpful.
 
Share this answer
 
v2
Comments
Sandeep Mewara 23-May-11 11:09am    
Wrapping code with PRE tags makes the answer readable.
 
Share this answer
 
Comments
NuttingCDEF 23-May-11 3:21am    
Good link - my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900