Link to home
Start Free TrialLog in
Avatar of testn1
testn1

asked on

cookie overwrite


I'm trying this but the cookie keeps the same value, how can i overwirte it?

Response.Cookies("ID").Value = ID

OR


'Dim c As New System.Web.HttpCookie("ID", strID)
'c.Expires = Now.AddDays(2)
'Response.Cookies.Add(c)


Request.Cookies("ID").Value  -- old value ...
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Avatar of testn1
testn1

ASKER

or   Response.Cookies.Item("ID").Value = ID   .. and nothing..
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of testn1

ASKER

hi gregory,

this time is vb .. it works fine on c#,  but can't overwrite/make it work on vb .net
Avatar of testn1

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.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration 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("Count") Is Nothing Then
            Dim cookie As HttpCookie = New HttpCookie("Count")
            cookie.Value = "0"
            cookie.Expires = Now.AddDays(100)
            Response.AppendCookie(cookie)
        Else
            Response.Cookies("Count").Value = CType(Request.Cookies("Count").Value, Integer) + 1
        End If
    End Sub

    Private Sub ShowCookieInfo()
        Response.Write("Old value = " + Request.Cookies("Count").Value)
    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
Avatar of testn1

ASKER

it's interesting...

i run this   If Request.Cookies.Item("Count") Is Nothing Then
            Dim cookie As HttpCookie = New HttpCookie("Count")
            cookie.Value = "0"
            cookie.Expires = Now.AddDays(100)
            Response.AppendCookie(cookie)
        Else
            Response.Cookies("Count").Value = CType(Request.Cookies("Count").Value, Integer) + 1
        End If
and the cookie is nothing... but if i do   If Request.Cookies.Item("Count") on the immediate window, i  get all the OLD values, the new one does not get assigned..

Avatar of testn1

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("Count") on the immediate window. It wont change until the next request.