?
Solved

Use of the HttpCookie Class not saving properly for some users

Posted on 2009-02-12
4
Medium Priority
?
212 Views
Last Modified: 2013-11-25
Our company has a website site with about 3000 customers.  Lately I've found that some of our customers (about 20) are unable to move through the site because their cookies are not being saved.  Some insist that the application worked for them as recently as last week.  A few have said that they do apply automatic updates to their computer, others are unsure.  All people that I've talked to are using IE7 and have the Override automatic cookie handling checked and are accepting both 1st and 3rd party cookies.  I do use session variables but do not use them on SQL Server because I only employ one web server and not a farm.  At first I thought this was an issue of saving and retrieving cookies between virtual directories, but I have provent that the users are not saving the cookie in the root directory.

When I use the Response.Cookies("TEST")("email") = emailAddr.Text method everything appears to work fine.  What am I doing wrong?

I create the cookies using a function that saves the cookie and another fuction to retreive the cookie.  I've created a cookie test page that spits out the values of the cookies.  The process works on most machines with the exception of these 20 or so customers, but the problem seems to be growing.  Has there been a Microsoft Update that prevents cookie handling?  If so how do we get around the issue?  

-- After the login process
            _cookie.SaveCookie("UserID", agentRow.ID, Me.Response, "60")
            _cookie.SaveCookie("UserName", agentRow.Name, Me.Response, "60")
            _cookie.SaveCookie("UserEmail", agentRow.EmailAddr, Me.Response, "60")
--
 
--Class for saving the cookie
Public Class clUtility
Public Sub SaveCookie(ByVal pstrKey As String, _
	ByVal pstrValue As String, _
	ByRef pobjResp As HttpResponse, _
	ByVal pstrExp As String)
		'method(objects)
		Dim lckCookie As HttpCookie
        Dim ldtNow As DateTime = DateTime.Now
		lckCookie = New HttpCookie(pstrKey, pstrValue.ToString.Trim)
        lckCookie.Expires = ldtNow.AddMinutes(CInt(pstrExp))
        'lckCookie.Secure = True
        pobjResp.Cookies.Add(lckCookie)
		'Destroy objects
		lckCookie = Nothing
		ldtNow = Nothing
End Sub
 
    Public Function GetCookie(ByVal pstrKey As String, _
    ByRef lobjReq As HttpRequest) As String
        'Method objects
        Dim lckCookie As HttpCookie
 
        'Get info from cookies
        With lobjReq.Cookies
            If .Count > 0 Then
                lckCookie = .Item(pstrKey)
                If Not lckCookie Is Nothing Then
                    Return lckCookie.Value
                Else
                    Return ""
                End If
            Else
                Return ""
            End If
        End With
        'Destroy objects
        lckCookie = Nothing
    End Function
 
End Class
--cookie test page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim oUtil As New clUtility
Response.Write("UserID: " & oUtil.GetCookie("UserID", Me.Request) & "<br />")
        Response.Write("UserName: " & oUtil.GetCookie("UserName", Me.Request) & "<br />")
        Response.Write("UserEmail: " & oUtil.GetCookie("UserEmail", Me.Request) & "<br />")
 
Response.Write("UserID: " & oUtil.GetCookie("UserID", Me.Request) & "<br />")
        Response.Write("UserName: " & oUtil.GetCookie("UserName", Me.Request) & "<br />")
        Response.Write("UserEmail: " & oUtil.GetCookie("UserEmail", Me.Request) & "<br />")
 
 
        Response.End()
 
    End Sub

Open in new window

0
Comment
Question by:AlexBB
  • 2
  • 2
4 Comments
 

Author Comment

by:AlexBB
ID: 23721340
Those articles didn't help.

I have been able to shadow a customer's machine and it was quite clear that cookies from our site were not being created.  Cookies from other sites were being created, but not ours.  

I do add a time value of 60 minutes to the cookie.  

_cookie.SaveCookie("UserID", agentRow.ID, Me.Response, "60")

Could it be that the customer has their time zone setting incorrect on their box?

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1500 total points
ID: 23721560
It could be one of many reasons. Try playing around on the computers where the cookies are not being saved. Changing time zone, synching the clock, changing security zones etc.
0
 

Author Closing Comment

by:AlexBB
ID: 31555891
The time zones for all known users with the issue were off.  Once they had logged into the system, their cookie automatically expired.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Loops Section Overview

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question