silentsam Posted April 28, 2003 Posted April 28, 2003 Apparently I've been up too long or something, but I seem to be having a problem with my cookies 'sticking'. The following code is suppose to check for a cookie, if it exists update the hit count, otherwise create a new one. The code seems to set the cookie fine for the session (or until IE is closed), but after that, the cookie doesn't seem to exist! Any thoughts/ideas/smacks upside my head??? Cheers! The exact code is below: Dim objUserCount as Integer = 0 Dim objSiteCount as Integer = 0 Dim objUserBrowser as HttpBrowserCapabilities = Request.Browser If objUserBrowser.Cookies Then 'Cookies Available Dim objUserCookie As HTTPCookie Dim objUserCookieCollection As HTTPCookieCollection Dim forLoop1 As Integer Dim objUserCookieCheck As Boolean = FALSE 'First We Need To Check To See If Our Cookie Exists objUserCookieCollection = Request.Cookies For forLoop1 = 0 TO objUserCookieCollection.Count - 1 objUserCookie = objUserCookieCollection(forLoop1) If objUserCookie.Name = "SPTHOMAS" Then 'Cookie Exists objUserCookieCheck = TRUE End If Next forLoop1 'After Checking We Need To Determine To Set/Create The Cookie If objUserCookieCheck Then 'Cookie Exists objUserCookie = objUserCookieCollection("SPTHOMAS") objUserCount = objUserCookie.Values("HitCount") objUserCount += 1 objUserCookie.Values("HitCount") = objUserCount 'objUserCookieCollection.Set(objUserCookie) Response.Cookies.Set(objUserCookie) Else 'Cookie Doesn't Exist Dim objUserCookieNew As New HTTPCookie("SPTHOMAS") objUserCookieNew.Values("HitCount") = 1 'objUserCookieCollection.Add(objUserCookieNew) Response.Cookies.Add(objUserCookieNew) objUserCount += 1 End If End If Quote
*Gurus* Derek Stone Posted April 28, 2003 *Gurus* Posted April 28, 2003 Give the cookie an expiration date and time. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.