I need to delete/expire a cookie in realtime while processing code. This is for when I empty my shopping cart, I want the cookie gone before the cart (which is ascx web control) processes as part of the normal postback procedure.
Can anyone tell me why this code doesn't immediatly expire the cookie?
' Set a cookie
System.Web.HttpContext.Current.Response.Cookies("GUID").Value = "HelloWorld"
' expire cookie
Dim aCookie As HttpCookie = Request.Cookies("GUID")
aCookie.Expires = DateTime.Now.AddDays(-1)
' see if we can still read the cookie, WE CAN!!! Not what we want!
Label1.Text = System.Web.HttpContext.Current.Request.Cookies("GUID").Value
After the postback event has completed the cookie is expired, but I really need the cookie expired before I finish executing my postback code!
I know I can do something like Response.Redirect(Request.Url.ToString) at the end of all my code to force 'another' refresh of my page to a pre postback state, but this means about 10 trips back to the database etc.