Hi,
So, I have a series of product pages and all I'd like to do is store the last 5 products viewed in a cookie so it can be displayed as a site-history. The problem I have isn't adding the five initial items to the cookie, its when they view 6, 7 or 10 items. Does anyone have any really decent suggestions on how to tackle this?
Currently I have this flawed logic (i have replaced the cookie name (xxx) for brevity);
Dim i As Integer = 0
Dim productcount As Integer = 0
If HttpContext.Current.Request.Cookies("xxx") Is Nothing Then
Dim gingernuts As New HttpCookie("xxx")
gingernuts.Values("productcount") = 0
gingernuts.Expires = DateTime.Now.AddDays(365)
HttpContext.Current.Response.Cookies.Add(gingernuts)
End If
productcount = HttpContext.Current.Request.Cookies("xxx")("productcount")
For i = 0 To productcount
If HttpContext.Current.Request.Cookies("xxx")("product" & i & "") = "" Then
HttpContext.Current.Response.Cookies("xxx")("product" & i & "") = Request.QueryString("id")
Else
HttpContext.Current.Response.Cookies("xxx")("product" & i & "") = HttpContext.Current.Request.Cookies("xxx")("product" & i & "")
End If
Next
If productcount = 5 Then
HttpContext.Current.Response.Cookies("xxx")("productcount") = 5
HttpContext.Current.Response.Cookies("xxx")("product0") = ""
Else
HttpContext.Current.Response.Cookies("xxx")("productcount") = productcount + 1
End If
Suggestions and critisism welcomed and appreciated.
Chris