got a strange issue for you.
I created a control that inserts a record into a Database and writes a cookie to the user’s machine. Here is the cookie writing code snippet:
protected void CreateCookie(Guid id, DateTime expires)
{
var oCookie = new HttpCookie("gsow");
oCookie.Value = id.ToString();
oCookie.Expires = expires;
HttpContext.Current.Response.Cookies.Add(oCookie);
}
Very simple, nothing fancy. The ID is passed from the function that writes the entry into the database and this ID is generated on the fly. Now here is the code for my cookie reading:
protected void Page_Load(object sender, EventArgs e)
{
var oCookie = HttpContext.Current.Response.Cookies["gsow"];
output.Text = "I am Here<br />";
if (oCookie != null)
output.Text += oCookie.Value;
else
output2.Text = "No Cookie.";
}
Once again, very simple. Here are the steps I have taken and duplicated several times:
- Create cookie/db entry by launching first page.
- Verify cookie/db entry exist (they do at this step, checked via Chrome’s cookie manager)
- Launch second page
Once I load up the second page, which should spit out the ID that I set earlier, the cookie still exists but it is Unset.
Here is a screenshot of the cookie after I load the first page:

And once I load the second page:

So from what I am seeing, the cookie’s value/expiration get stripped out when I load the second page. Anyone have any ideas on why this is happening?
Thanks
To the best of my knowledge, you should be retrieving cookies using the Request object, not the Response object.