I'm doing the following to set a cookie value:
HttpCookie mycookie = new HttpCookie("mycookie"); mycookie.Value = "value1"; // Case sensitivity mycookie.Expires = DateTime.Now.Add(1); HttpContext.Current.Response.Cookies.Add(mycookie);
Sometime later, I check the cookie using:
HttpCookie mycookie = HttpContext.Current.Request.Cookies["mycookie"];
I notice it still has an older value:
mycookie.Value == "oldValue"
I can even check the cookie immediately after setting it and the value I've set isn't there. It's still the old value.
What is happening that the value isn't being set and how can I set it???
Try this, you need to remove it and then add it
var response = HttpContext.Current.Response; response.Cookies.Remove("mycookie"); response.Cookies.Add(cookie);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With