Problems With Cookies

silentsam

New member
Joined
Apr 3, 2003
Messages
1
Location
Burlington, Ontario
Apparently Ive 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 doesnt seem to exist!

Any thoughts/ideas/smacks upside my head???

Cheers!

The exact code is below:

Code:
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 Doesnt Exist
		Dim objUserCookieNew As New HTTPCookie("SPTHOMAS")
		objUserCookieNew.Values("HitCount") = 1
		objUserCookieCollection.Add(objUserCookieNew)		
		Response.Cookies.Add(objUserCookieNew)
		objUserCount += 1
	End If
			
End If
 
Back
Top