I created a simple cart. We need something specific for our needs, a long story. Anyway, I store the basket object in a cookie. This works well, but I am having trouble removing the cookie basket from the class. The cart object contains a collection of products (iList). Here is the code I use to delete the cookie: My empty recycle code:
Dim currentCookie As HttpCookie = HttpContext.Current.Response.Cookies(cookieName)
currentCookie.Expires = DateTime.Now.AddYears(-30)
HttpContext.Current.Response.Cookies.Add(currentCookie)
My code is LoadCartFromCookie:
if not HttpContext.Current.Request.Cookies(theCookieName) is nothing then
_cart = CType(HttpContext.Current.Request.Cookies(theCookieName).value,Cart)
End If
The basket class constructor first tries to load the basket from the cookie. If it finds a cookie, it loads the cart object, otherwise it creates a new cart instance without any details. For some reason, even if I run the delete cookie (Empty cart) code and then run the LoadCartFromCookie code (from inside the Cart class), it still loads the expired cookie. Any suggestions? I thought this might be a browser issue, but I tried IE8, FF 3.5, and Chrome. If I try to find an expired cookie (Request.Cookies (theName)) inside the codebehind and ASPX pages, it never finds it. This is what I want him to do inside the class.
Daniel
source
share