fgignac@neomedia.com (Frederic Gignac) wrote in
news:8878eaae.0307070719.23f5f551@posting.google.c om:
[color=blue]
> 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
> ?[/color]
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.
http://www.crtimmonsinc.com/