Hi,
I tried this and the damned cookie is still there!
Response.Cookies[admin.COOKIE_USER].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[admin.COOKIE_PSWD].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[admin.COOKIE_USER].Value = null;
Response.Cookies[admin.COOKIE_PSWD].Value = null;
Response.Cookies.Remove(admin.COOKIE_USER);
Response.Cookies.Remove(admin.COOKIE_PSWD);
Maybe it's the way I set the cookie?
HttpCookie cookieUsr = new HttpCookie(COOKIE_USER, username);
cookieUsr.Expires = DateTime.Now.AddDays(1000);
HttpCookie cookiePwd = new HttpCookie(COOKIE_PSWD, encryptedValue);
cookiePwd.Expires = DateTime.Now.AddDays(1000);
Response.SetCookie(cookieUsr);
Response.SetCookie(cookiePwd);
Thanks for any help!
Stephane
"Chris R. Timmons" wrote:
"=?Utf-8?B?U3RlcGhhbmU=?=" <St******@discussions.microsoft.com>
wrote in news:9E**********************************@microsof t.com:
Hi,
I have a login page where if the user wants his access codes to
be saved are set into a cookie. In the logout page, I want to
delete those cookies. I tried this and this is not working at
all:
if (Request.Cookies[COOKIE_USER] != null
&& Request.Cookies[admin.COOKIE_PSWD] != null)
{
Response.Cookies[COOKIE_USER].Value = null;
Response.Cookies[COOKIE_PSWD].Value = null;
Response.Cookies.Remove(COOKIE_USER);
Response.Cookies.Remove(COOKIE_PSWD);
}
If I do a response.write like this right after or on another
page, it shows that the cookies are still set:
Response.Write((Request.Cookies[COOKIE_USER] == null) + " " +
Request.Cookies[COOKIE_USER].Value + " ");
Response.Write((Request.Cookies[COOKIE_PSWD] == null) + " " +
Request.Cookies[COOKIE_PSWD].Value);
Why is this not working? How do we remove user's cookie?
Stephane,
Set the cookie's expiration date to sometime in the past. When it is
sent back to the browser, the browser will look at the cookie's date
and determine it has expired and delete it. For example:
Response.Cookies[COOKIE_USER].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[COOKIE_PSWD].Expires = DateTime.Now.AddDays(-10);
--
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/