Search code examples
c#sharepoint-2010httpcookiehttpcookiecollection

Sharepoint 2010 setting a cookie expiration date seemsto work when viewed from browser but server code sees 01/01/0001 expiration


here is the to add the cookie to the request

    HttpCookie cookie = new HttpCookie(myCookie);
    cookie.Expires = DateTime.Now.AddDays(30);
    cookie.Value = myValue;
    cookie.Domain = myDomain;
    cookie.HttpOnly = true;
    response.Cookies.Add(cookie);

Seems fine, until during a Sharepoint 2010 context.PostAuthenticateRequest event when i try to read the cookie

    HttpCookieCollection cookies = request.Cookies;
        HttpCookie tosCookie = cookies.Get(TOS_COOKIE_KEY_ACKNOWLEDGEMENT);
        tosCookie.Expires

i get the date 01/01/0001 when in the browser i see the cookie expiration date as 12/6/2012


Solution

  • Yes, server does not know expiration time on incoming cookies.

    Browser does not send expired cookies to server and does not in any way let server know what cookie expiration is.