Private Sub rblMode_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles rblMode.SelectedIndexChanged
Const CTL_MODE = "rblMode"
Response.Cookies(CTL_MODE).Expires = DateTime.Now.AddDays(1)
Response.Cookies(CTL_MODE).Value = rblMode.SelectedValue
End Sub
This code tells me the cookie exists after creating it:
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim output As New System.Text.StringBuilder
Dim aCookie As HttpCookie
For i As Integer = 0 To Request.Cookies.Count - 1
aCookie = Request.Cookies(i)
output.Append(Server.HtmlEncode(aCookie.Name)).Append(" : ").Append(Server.HtmlEncode(aCookie.Value)).Append(vbCrLf)
Next
tbResponse.Text = output.ToString()
End Sub
Everything seems to work while the application runs. However, when I restart, the cookie is gone. Why? I want my cookies to persist.
everytime you change the cookie value, you need to set cookie expiration date too. So make sure once you are changing its value somewhere in your code, you need to put an expiration date again.
Marked as answer by geosync on Jan 31, 2012 08:29 PM
geosync
Contributor
2370 Points
768 Posts
Cookies don't persist...
Jan 30, 2012 08:15 PM|LINK
This code creates a cookie:
Private Sub rblMode_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles rblMode.SelectedIndexChanged Const CTL_MODE = "rblMode" Response.Cookies(CTL_MODE).Expires = DateTime.Now.AddDays(1) Response.Cookies(CTL_MODE).Value = rblMode.SelectedValue End SubThis code tells me the cookie exists after creating it:
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load Dim output As New System.Text.StringBuilder Dim aCookie As HttpCookie For i As Integer = 0 To Request.Cookies.Count - 1 aCookie = Request.Cookies(i) output.Append(Server.HtmlEncode(aCookie.Name)).Append(" : ").Append(Server.HtmlEncode(aCookie.Value)).Append(vbCrLf) Next tbResponse.Text = output.ToString() End SubEverything seems to work while the application runs. However, when I restart, the cookie is gone. Why? I want my cookies to persist.
What am I missing here?
Sum8
Contributor
4141 Points
931 Posts
Re: Cookies don't persist...
Jan 31, 2012 05:44 AM|LINK
Are you closing your web browser while restarting the application?
In that case check whether browser settings are set in that way to clear the cookies on clising the browser.
Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
Ebad86
Member
202 Points
37 Posts
Re: Cookies don't persist...
Jan 31, 2012 06:16 AM|LINK
everytime you change the cookie value, you need to set cookie expiration date too. So make sure once you are changing its value somewhere in your code, you need to put an expiration date again.