Hi Team
I had developed a Web application. in that i want to store cookies for my username.
any help greatly appreciated...
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dorababu MekaRank #457 · 5.5K reputationPosted May 12, 2011, 1:02 AM EDT
http://msdn.microsoft.com/en-us/library/ms178194.aspx#Y1938
Ankit NandekarRank #703 · 3.4K reputationPosted May 12, 2011, 1:21 AM EDT
HttpCookie obj=new HttpCookie("MyCookieName");
obj.Value=TextBox1.Text;
Response.Cookies.Add(obj);
write this code to read cookies
string CookieValue;
// We need to perform this check first, to avoid null exception
// if cookie not exists
if(Request.Cookies["MyCookieName"] != null)
CookieValue = Request.Cookies["MyCookieName"].Value;
To set expiry date of cookies write this code bellow the line of create cookies.
obj.Expires = DateTime.Now.AddDays(1);
To delete existing cookie we actually just set its expiration time to some time in the past. You can do it with code like this:
obj.Expires== DateTime.Now.AddDays(-1);
Andrew FensterRank #983 · 2K reputationPosted May 12, 2011, 7:06 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted May 12, 2011, 10:10 AM EDT