testn1
asked on
cookie overwrite
I'm trying this but the cookie keeps the same value, how can i overwirte it?
Response.Cookies("ID").Val
OR
'Dim c As New System.Web.HttpCookie("ID"
'c.Expires = Now.AddDays(2)
'Response.Cookies.Add(c)
Request.Cookies("ID").Valu
basic cookie tutorial .... http://www.geekpedia.com/tutorial81_Handling-cookies-in-ASP-.NET.html
ASKER
or Response.Cookies.Item("ID" ).Value = ID .. and nothing..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi gregory,
this time is vb .. it works fine on c#, but can't overwrite/make it work on vb .net
this time is vb .. it works fine on c#, but can't overwrite/make it work on vb .net
ASKER
looks like the problem is overwriting the cookie
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara tion As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub ChangeCookieInfo()
If Request.Cookies.Item("Coun t") Is Nothing Then
Dim cookie As HttpCookie = New HttpCookie("Count")
cookie.Value = "0"
cookie.Expires = Now.AddDays(100)
Response.AppendCookie(cook ie)
Else
Response.Cookies("Count"). Value = CType(Request.Cookies("Cou nt").Value , Integer) + 1
End If
End Sub
Private Sub ShowCookieInfo()
Response.Write("Old value = " + Request.Cookies("Count").V alue)
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ChangeCookieInfo()
ShowCookieInfo()
End Sub
End Class
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub ChangeCookieInfo()
If Request.Cookies.Item("Coun
Dim cookie As HttpCookie = New HttpCookie("Count")
cookie.Value = "0"
cookie.Expires = Now.AddDays(100)
Response.AppendCookie(cook
Else
Response.Cookies("Count").
End If
End Sub
Private Sub ShowCookieInfo()
Response.Write("Old value = " + Request.Cookies("Count").V
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ChangeCookieInfo()
ShowCookieInfo()
End Sub
End Class
ASKER
it's interesting...
i run this If Request.Cookies.Item("Coun t") Is Nothing Then
Dim cookie As HttpCookie = New HttpCookie("Count")
cookie.Value = "0"
cookie.Expires = Now.AddDays(100)
Response.AppendCookie(cook ie)
Else
Response.Cookies("Count"). Value = CType(Request.Cookies("Cou nt").Value , Integer) + 1
End If
and the cookie is nothing... but if i do If Request.Cookies.Item("Coun t") on the immediate window, i get all the OLD values, the new one does not get assigned..
i run this If Request.Cookies.Item("Coun
Dim cookie As HttpCookie = New HttpCookie("Count")
cookie.Value = "0"
cookie.Expires = Now.AddDays(100)
Response.AppendCookie(cook
Else
Response.Cookies("Count").
End If
and the cookie is nothing... but if i do If Request.Cookies.Item("Coun
ASKER
definitely is not overwrtiting the cookie value..
you mean that you set Response and Request still has the old value ? try looking at Response.Cookies.Item("Cou nt") on the immediate window. It wont change until the next request.