I have created a simple shopping cart application. We needed something specific to our needs, long story. Anyway, I am storing the cart object in a cookie. That work fine, but I am having trouble with deleting the cart cookie from within the class. The cart object contains a collection of products (iList). Here is the code I use to delete the cookie: My Empty Cart Code:
Dim currentCookie As HttpCookie = HttpContext.Current.Response.Cookies(cookieName)
currentCookie.Expires = DateTime.Now.AddYears(-30)
HttpContext.Current.Response.Cookies.Add(currentCookie)
My LoadCartFromCookie code:
if not HttpContext.Current.Request.Cookies(theCookieName) is nothing then
_cart = CType(HttpContext.Current.Request.Cookies(theCookieName).value,Cart)
End If
My cart class constructor first tries to load the cart from the cookie. If it finds the cookie then it loads the cart object otherwise it creates a new instance of the cart without any details. For some reason even if I run the delete cookie (Empty cart) code and then run my LoadCartFromCookie code (From inside the Cart class) it still loades the expired cookie. Any thoughts? I thought it might have been a browser issue, but I tried IE8, FF 3.5, and Chrome. If inside the codebehind for and ASPX page I try looking for the expired cookie (Request.Cookies(theName)) , it never finds it. Which is what I want it to do inside the class.
Daniel