Expiration date seems not to work

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Expiration date seems not to work

    Hiya all,

    My buddy and I got a bug with the expiration date of a cookie. When we
    want to look out the expiration date, the only thing we've got, it's
    01/01/0001.

    As we know, when we want to create a persitant cookie, we have to put
    a expiration date, otherwise, it will be a session cookie. So here our
    code :

    HttpCookie cookie = new HttpCookie(m_propertyID);
    cookie.Value = m_property;
    if (m_temporaryCookie == false)
    {
    cookie.Expires = DateTime.MaxValue;
    }
    HttpContext.Current.Response.Cookies.Add(cookie);

    And when we want to see the value :

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

    if ( cookie != null)
    {
    HttpContext.Current.Response.Write(cookie.Expires) ;
    }


    With that, we've always got the 01/01/0001. If you have any ideas to
    help us, let us know.

    Btw, sorry for the english typos :)
    Frederic Gignac Guest

  2. Similar Questions and Discussions

    1. Disabling Printing, Saving, Editing, andadding an Expiration date to a PDF file using theAcrobat.
      Is it possible to disable Printing, Saving, Editing, and add an Expiration date to a PDF file using the Acrobat SDK?
    2. Query by date doesn't work
      I'm using Informix 9.3, If I run the query in Informix it works, when I run the same query in ColdFusion I get a string to date conversion. I'm...
    3. Cookie Expiration Date
      :confused; Can anyone help me figure out how to change the date that my coldfusion server sets for expiration on client housed cookies? I have run...
    4. SQL/ASP.NET getting DATE to work in query
      I'm grabbing today's date with some ASP.net code: Dim Today As Date Today = Microsoft.VisualBasic.Today() I'm then trying to run a SQL query...
    5. Reala 6 years after expiration date
      I just thought some of you might find interesting the following: I had a brick (20 rolls) of Reala 100 speed film in my refrigerator, not the...
  3. #2

    Default Re: Expiration date seems not to work

    [email]fgignac@neomedia.com[/email] (Frederic Gignac) wrote in
    news:8878eaae.0307070719.23f5f551@posting.google.c om:
    > Thank you Chris for the link. Besides I've got a 500 error page,
    > the Google cache saves me ;)
    >
    > After reading it, I'm now aware that we can't do what we will
    > attempt to.
    >
    > We want to know if the cookie is non-persistant or a persistant
    > one. So we think to look for the expires value of the cookie to
    > let us know if it's a non or a persistant one.
    >
    > Obviously, this isn't the good method after reading the
    > article...
    >
    > Any suggests to make the difference between the two types of
    > cookies ? Is there a method or something that we haven't see yet
    > ?
    One way to tell the difference would be to set a value in the cookie:

    // Persistent cookie.
    HttpCookie cookie = new HttpCookie("MyCookie");
    cookie.Expires = DateTime.AddDays(10);
    cookie.Values["Persistent"] = "true";
    cookie.Values["Data"] = "Hello, world!";
    HttpContext.Current.Response.Cookies.Add(cookie);

    or

    // Non-persistent cookie because no expiraton date is set.
    // Will be destroyed when the user closes their browser.
    HttpCookie cookie = new HttpCookie("MyCookie");
    cookie.Values["Persistent"] = "false";
    cookie.Values["Data"] = "foo";
    HttpContext.Current.Response.Cookies.Add(cookie);

    You can use code like this to see if the cookie is persistent or not:

    HttpCookieCollection cookies = HttpContext.Current.Request.Cookies;
    bool isMyCookiePersistent = false;

    if (cookies["MyCookie"] != null)
    {
    isMyCookiePersistent =
    (cookies["MyCookie"].Values["Persistent"] == "true");
    }


    Hope this helps.

    Chris.
    -------------
    C.R. Timmons Consulting, Inc.
    [url]http://www.crtimmonsinc.com/[/url]
    Chris R. Timmons Guest

  4. #3

    Default Re: Expiration date seems not to work

    "Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:<Xns93B18E888DFABcrtimmonscrtimmonsin@207.46. 248.16>...
    > > One way to tell the difference would be to set a value in the cookie:
    >
    > // Persistent cookie.
    > HttpCookie cookie = new HttpCookie("MyCookie");
    > cookie.Expires = DateTime.AddDays(10);
    > cookie.Values["Persistent"] = "true";
    > cookie.Values["Data"] = "Hello, world!";
    > HttpContext.Current.Response.Cookies.Add(cookie);
    >
    > or
    >
    > // Non-persistent cookie because no expiraton date is set.
    > // Will be destroyed when the user closes their browser.
    > HttpCookie cookie = new HttpCookie("MyCookie");
    > cookie.Values["Persistent"] = "false";
    > cookie.Values["Data"] = "foo";
    > HttpContext.Current.Response.Cookies.Add(cookie);
    >
    > You can use code like this to see if the cookie is persistent or not:
    >
    > HttpCookieCollection cookies = HttpContext.Current.Request.Cookies;
    > bool isMyCookiePersistent = false;
    >
    > if (cookies["MyCookie"] != null)
    > {
    > isMyCookiePersistent =
    > (cookies["MyCookie"].Values["Persistent"] == "true");
    > }
    >
    >
    > Hope this helps.
    >
    > Chris.
    > -------------
    > C.R. Timmons Consulting, Inc.
    > [url]http://www.crtimmonsinc.com/[/url]

    Thanks again ! It was this solution that we've been thinking last
    week, but since a module administrate the cookie, we will have to
    modify a hell lot of code. Since we have to give our project within
    days, we won't have the time to do all these modifications. For sure,
    for next projects, we'll change our module.

    Thank you anyway :)
    Fred
    Frederic Gignac Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139