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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted May 12, 2011, 2:10 PM
Andrew FensterPosted May 12, 2011, 11:06 AM
Ankit NandekarPosted May 12, 2011, 5:21 AM
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);
Dorababu MekaPosted May 12, 2011, 5:02 AM
http://msdn.microsoft.com/en-us/library/ms178194.aspx#Y1938