If you are new to using cookies then probably you must have wrote similar to the below code to Add & Remove cookies.
Adding Cookie:
HttpCookie test = new HttpCookie("Test");
test.Value = "Testing Data";
Response.Cookies.Add(test);
Removing Cookie: Either of one.
Response.Cookies.Remove("Test");
Response.Cookies.Clear();
But removal of cookie does not work this way.
Reason:
Remove() and Clear() remove a cookie instance or all cookies from the Response respectively.
They do not do anything on the client, it is a disconnected architecture. Therefore, in order to invalidate (remove) the cookie from the Request as sent by the client - for the next request and subsequent requests you need a quick fix.
Quick Fix:
Set the cookie expirey to be less than the next request time
Response.Cookies["Test"].Expires = DateTime.Now.AddDays(-1);
Hope it it useful.
Thanks & Regards,
Arun Manglick
SMTS || Microsoft Technology Practice || Bridgestone - Tyre Link || Persistent Systems || 3023-6258
DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.
No comments:
Post a Comment