locked
wrong cookie expiration date RRS feed

  • Question

  • User41995013 posted

    Hi there:

    I cannot make a cookie expiration date to have a correct date, it's always 1-1-0001.

    my cookie creation is like this:

    HttpCookie cookie = new HttpCookie("CookieData");

    cookie["Name"] = txtName.Text.Trim();

    cookie.Expires = DateTime.Now.AddDays(1);

    Response.Cookies.Add(cookie);

     

    And I'm retrieving like (in other form):

    HttpCookie cookie;

    cookie = Request.Cookies["CookieData"];

    if (cookie != null) {

       lblName.Text = cookie["Name"];

       lblExpirationDate.Text = cookie.Expires.ToLongDateString();

     }

     

    lblExpirationDate.Text shows 1-1-0001 as the expiration date for the cookie, it should show tomorrows date (DateTime.Now.AddDays(1);).

    Can anybody tell my what am I missing here?

    Rafael

     

     

    Friday, February 26, 2010 11:10 AM

Answers

  • User-55773023 posted

    http://msdn.microsoft.com/en-us/library/ms178194.aspx


    The browser is responsible for managing cookies, and the cookie's expiration time and date help the browser manage its store of cookies. Therefore, although you can read the name and value of a cookie, you cannot read the cookie's expiration date and time. When the browser sends cookie information to the server, the browser does not include the expiration information. (The cookie's Expires property always returns a date-time value of zero.)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 26, 2010 9:21 PM

All replies

  • User1047930591 posted

    Whttp://www.breakoutseason.com/derrick_ribilla/cookie_expires_expiration_date_problem.htm

    May be this help you

    Well, this is a bit tough to me also, hmmm

    Why dn you try to store expirey date inside cookie, like value. i hope this ld work

    Friday, February 26, 2010 11:59 AM
  • User-55773023 posted

    http://msdn.microsoft.com/en-us/library/ms178194.aspx


    The browser is responsible for managing cookies, and the cookie's expiration time and date help the browser manage its store of cookies. Therefore, although you can read the name and value of a cookie, you cannot read the cookie's expiration date and time. When the browser sends cookie information to the server, the browser does not include the expiration information. (The cookie's Expires property always returns a date-time value of zero.)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 26, 2010 9:21 PM