Results 1 to 3 of 3

Thread: cookies question

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    cookies question

    I am using 2005 Beta 2 with the following code:
    VB Code:
    1. Private Const SECURITY_COOKIE As String = "Security"
    2.     Private Const GUID_KEY As String = "GUID"
    3.  
    4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    5.         Dim Cookie As HttpCookie = Request.Cookies.Item(SECURITY_COOKIE)
    6.         Dim Passed As Boolean
    7.         If Not (Cookie Is Nothing) Then
    8.             Dim GUID As String = Cookie.Item(GUID_KEY)
    9.             If GUID = String.Empty Then
    10.                 CreateSecurityCookie()
    11.             Else
    12.                 Passed = True
    13.             End If
    14.         Else
    15.             'always this line...always :o(
    16.             CreateSecurityCookie()
    17.         End If
    18.         Dim Woof As HttpCookie = Request.Cookies.Item(SECURITY_COOKIE)
    19.         If Woof Is Nothing Then
    20.             'never here as it's just been created above, so of course it exists
    21.             Passed = False
    22.         End If
    23.     End Sub
    24.  
    25.     Private Sub CreateSecurityCookie()
    26.         Dim NewCookie As New HttpCookie(SECURITY_COOKIE)
    27.         Dim dt As DateTime = DateTime.Now
    28.         Dim ds As New TimeSpan(0, 0, 20, 0)
    29.         NewCookie.Expires = dt.Add(ds)
    30.         NewCookie.Item(GUID_KEY) = "Woof"
    31.         Request.Cookies.Add(NewCookie)
    32.     End Sub
    But it always hits that line of code when I refresh the page...surely 20min lifespan is long enough. The cookie is always NOTHING when I refresh the page.
    How come it doesn't remember the cookie?

    Am I being daft?

    Woof

  2. #2

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: cookies question

    Guess its time for that bedtime snack of cookies and milk.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width