Cookies not working
-
Hi, Just a small code to check whether cookies are getting stored/retrived or not. Check the code below: protected void Button1_Click(object sender, EventArgs e) { Response.Cookies["userName"].Value = "patrick"; } protected void Button2_Click(object sender, EventArgs e) { if (Request.Cookies["userName"] == null) Label1.Text = "Cookie not found"; else Label1.Text=Server.HtmlEncode(Request.Cookies["userName"].Value); } ------------------------ When I try to retrieve the cookie values on button2_click, it is not retrieved although I have set the option "accept all cookies" in IE 6. Where is issue?
-
Hi, Just a small code to check whether cookies are getting stored/retrived or not. Check the code below: protected void Button1_Click(object sender, EventArgs e) { Response.Cookies["userName"].Value = "patrick"; } protected void Button2_Click(object sender, EventArgs e) { if (Request.Cookies["userName"] == null) Label1.Text = "Cookie not found"; else Label1.Text=Server.HtmlEncode(Request.Cookies["userName"].Value); } ------------------------ When I try to retrieve the cookie values on button2_click, it is not retrieved although I have set the option "accept all cookies" in IE 6. Where is issue?
Is this happening between postbacks. I think it should work if you are not working cookieless. I checked and found working. :confused: Also check whether you have re initialized the value on page_load section.
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
Is this happening between postbacks. I think it should work if you are not working cookieless. I checked and found working. :confused: Also check whether you have re initialized the value on page_load section.
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
Hi, Just a small code to check whether cookies are getting stored/retrived or not. Check the code below: protected void Button1_Click(object sender, EventArgs e) { Response.Cookies["userName"].Value = "patrick"; } protected void Button2_Click(object sender, EventArgs e) { if (Request.Cookies["userName"] == null) Label1.Text = "Cookie not found"; else Label1.Text=Server.HtmlEncode(Request.Cookies["userName"].Value); } ------------------------ When I try to retrieve the cookie values on button2_click, it is not retrieved although I have set the option "accept all cookies" in IE 6. Where is issue?
The above code is working now. IF i write the below: Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1); There could be any value of expiry. Why is it mandatory? I mean if we donot set it, does it mean it will not create at all. Moreover, without seeing the code, how to verify the expiry time of a cookie?