cookie expiry date 01/01/0001

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Ray (anonymous_at_discussions.microsoft.com)
Date: 04/22/04


Date: Wed, 21 Apr 2004 19:56:01 -0700

Below is the code to save the cookie and set the expiry date of the cookie

Response.Cookies["demo"].Value ="Hello";
DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,10,0);
Response.Cookies ["demo"].Expires = dt.Add(ts);

Below is the code to retrieve the stored cookie.

if (!Page.IsPostBack) {
       HttpCookie dcookie = Request.Cookies["demo"];
       if (dcookie != null) {
                 urlevel.Text = dcookie.Values["level"];
         urname.Text = dcookie.Values["user"];
         daysx.Text = Convert.ToString(Request.Cookies["demo"].Expires);
        }
       else
             Response.Redirect ("haha.htm");
   }

When I display the Response.Cookies ["demo"].Expires = dt.Add(ts); it returns the current date + 10 minutes
But the days.Text returns 01/01/0001. Why? Please help Thanks.

Ray



Relevant Pages

  • Re: problem with slidingExpiration
    ... DateTime dt= DateTime.Now; ... //cripto l'authentication ticket ... string cookiestr = FormsAuthentication.Encrypt; ... //aggiungo il cookie ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: problem with slidingExpiration
    ... > true since I want permit users to stay logged in when they use the web ... > DateTime dt= DateTime.Now; ... > string cookiestr = FormsAuthentication.Encrypt; ... > //aggiungo il cookie ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • problem with slidingExpiration
    ... I'm trying to use Forms authentication with slidingExpiration option set to ... true since I want permit users to stay logged in when they use the web ... DateTime dt= DateTime.Now; ... //aggiungo il cookie ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Do I need to delete my cookie before re-adding it?
    ... a cookie that expires in 1 day. ... Before adding the cookie each time, do I need to delete the previous cookie? ... Dim objCookie As HttpCookie ... Dim dt As DateTime = DateTime.Now ...
    (microsoft.public.dotnet.framework.aspnet)
  • cookie expiry date problem
    ... Below is the code to save the cookie and set the expiry date of the cookie ... DateTime dt = DateTime.Now; ... TimeSpan ts = new TimeSpan; ...
    (microsoft.public.dotnet.framework.aspnet.security)