Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Check to see if the cookie is there...
Dim MyCookie As HttpCookie = Request.Cookies("Preferences")
'If the cookie is not already there...
If MyCookie Is Nothing Then
'Create a new cookie
MyCookie = New HttpCookie("Preferences")
'Assign som values
MyCookie("FullName") = "Steve Schimsky"
MyCookie("Address") = "27 Bradford Lane"
MyCookie.Expires = DateTime.Now.AddDays(2)
'Add the cookie
Response.Cookies.Add(MyCookie)
Else
'Show the contents of the cookie
Response.Write("Welcome back " & MyCookie("FullName") & " of " & MyCookie("Address"))
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Set the cookie to expire
Dim MyCookie As HttpCookie = Request.Cookies("Preferences")
MyCookie.Expires = Now.AddDays(-1)
Response.Cookies.Add(MyCookie)
End Sub