cookie troubles

Discussion in 'ASP .Net' started by Owen, Jan 7, 2005.

  1. Owen

    Owen Guest

    I have a web app that is a mixture of ASP and ASP.NET pages. Largely the
    only data passed between them is via the querystring, or by reading from a
    database. However there is a requirement for one part to communicate via a
    cookie. (Please dont ask me to go into why, I don't have time).

    In my ASP page, I created a cookie and put a value in it:

    Response.Cookies("MyCookieName") = "OriginalValue"
    Response.Cookies("MyCookieName").Expires = CDate("31/12/2030")
    Response.Cookies("MyCookieName").Path = "/"

    That works great. The cookie appears in the Temporary Files folder on disk,
    with the distant expiry date as expected. Furthermore I look inside the
    cookie using Notepad, and it shows the "OriginalValue" that I put in.

    Now I want to read that same cookie from my ASP.NET page, using:

    Dim CookieVal as String = Request.Cookies.Item("MyCookieName").Value

    ....which seems to work perfectly OK. It returns "OriginalValue" that I put
    in there using ASP.

    Now, the problem is that I cannot seem to *update* the cookie via my ASP.NET
    page:

    Dim c As HttpCookie = Request.Cookies.Item("MyCookieName")
    c.Value = "MyNewValue"


    After running the above code, I take a look inside the cookie, but the
    "OriginalValue" remains. No errors occurred, it did not crash, but didn't
    work either. I cannot understand why.

    What am I missing?

    Thanks
    Owen
    PS. replies cc'd via email appreciated as this is quite urgent
    Owen, Jan 7, 2005
    #1
    1. Advertising

  2. Owen

    Exception Guest

    "Owen" wrote:

    > Now, the problem is that I cannot seem to *update* the cookie via my
    > ASP.NET
    > page:
    >
    > Dim c As HttpCookie = Request.Cookies.Item("MyCookieName")
    > c.Value = "MyNewValue"


    IIRC, you should add : Response.Cookies.Add(c);

    Steven

    - - -
    Exception, Jan 7, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben
    Replies:
    3
    Views:
    5,791
    Steven Cheng[MSFT]
    Jun 3, 2004
  2. Shapper

    Cookie and Session Cookie Questions.

    Shapper, Apr 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    551
  3. =?Utf-8?B?UGF1bA==?=

    Cookie Question (IP as domain and cookie file location)

    =?Utf-8?B?UGF1bA==?=, Jan 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,462
    Bruce Barker
    Jan 10, 2006
  4. Arjen

    Cookie troubles

    Arjen, Feb 22, 2006, in forum: HTML
    Replies:
    0
    Views:
    371
    Arjen
    Feb 22, 2006
  5. Ben Hearsum

    Cookie.py troubles.

    Ben Hearsum, Jul 27, 2003, in forum: Python
    Replies:
    1
    Views:
    313
    John J. Lee
    Jul 28, 2003
Loading...

Share This Page