I have the following code:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["MyTestCookie"] == null)
{
string str = "Some String";
HttpCookie myCookie = new HttpCookie("MyTestCookie")
{
Value = str,
Expires = DateTime.Now.AddYears(50)
};
HttpContext.Current.Response.SetCookie(myCookie);
}
}
But it works until I close my browser. If I close my browser and compile and run my project again the code inside the if block will executes again. So my question is why my cookies expiration doesn't work and the cookie is expiring after I close the browser?
Some notes:
- This is in development and localhost and my port is not changed during several running.
- I've checked my browser settings and it doesn't deletes cookies upon close.