Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...