Problems With Cookies In ASP.NET/VB.NET 
Author Message
 Problems With Cookies In ASP.NET/VB.NET

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 objDateTime As DateTime = DateTime.Now()
Dim objTimeSpan As New TimeSpan(365,0,0,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)
    Else
    'Cookie Doesn't Exist
        Dim objUserCookieNew As New HTTPCookie("SPTHOMAS")
        objUserCookieNew.Values("HitCount") = 1
        objUserCookie.Expires = objDateTime.Add(objTimeSpan)
        objUserCookieCollection.Add(objUserCookie)
        objUserCount += 1
    End If

End If



Sat, 15 Oct 2005 02:49:51 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. ADO.NET with ASP.NET using VB.NET

2. Date problems with XML in ASP.NET / VB.NET- newbie question

3. problem with crystal report for .net in asp.net

4. Survey on ASP/VS6.0 versus ASP.NET/VS.NET

5. Visual Basic.NET , ASP or ASP.NET

6. VB6/ASP vs .NET/ASP.NET development

7. How can I create the cookies in asp.net (back end sybase)

8. REXEC from ASP.NET or VB.NET

9. VB.net and asp.net

10. VB.net and ASP.net what is the difference

11. ASP.net VB.Net Stored Procedures in SQL Server

12. REXEC from ASP.NET or VB.NET

 

 
Powered by phpBB® Forum Software