views:

41

answers:

0

Is it possible to update an ASP.NET cookies value without also having to update the expiration time? I have found that if I try and update a Cookie without also updating the expiration, that cookie no longer exists. I have the following code which I am try to modify. What's the point of having an expiration, if every time the cookie value is updated, so is the expiration?

        HttpCookie cookie = HttpContext.Current.Request.Cookies[constantCookie];

        if (cookie == null)
            cookie = new HttpCookie(constantCookie);

        cookie.Expires = DateTime.Now.AddYears(1);
        cookie.Value = openClose;
        HttpContext.Current.Response.Cookies.Set(cookie);