Help with cookies

Discussion in 'ASP .Net' started by Josh King, Jul 20, 2003.

  1. Josh King

    Josh King Guest

    I'm having trouble accessing my cookies after they're set. If I do a
    response.write on the cookie value immediately after it's set in code,
    it writes out the cookie value as it should. But when I come back to
    the page the cookie is null and I can no longer access it.

    Here's my add code:

    DateTime expireCookie = DateTime.Now;
    expireCookie.AddYears(5);

    HttpCookie vandalayCookie = new HttpCookie("VandalayCookie");
    vandalayCookie.Expires = expireCookie;
    vandalayCookie.Values.Add("UserName",opUser.SelectedValue);
    vandalayCookie.Values.Add("Password",txtPassword.Text);

    //Write cookie out to client
    Response.Cookies.Add(vandalayCookie);

    Here's my retrieval code:

    HttpCookie VandalayCookie = Request.Cookies["VandalayCookie"];

    if (VandalayCookie != null)
    {
    opUser.SelectedValue = VandalayCookie.Values.Get("UserName");
    txtPassword.Text = VandalayCookie.Values.Get("Password");

    }

    My retrieval code always evaluates the VandalayCookie as null and
    never retrieve the values. I've even added my site to my list of
    trusted sites and sites that I accept cookies from and still no luck.
    Is there something I'm not doing right?

    Thanks,
    Josh
    Josh King, Jul 20, 2003
    #1
    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. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,451
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,501
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    647
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    498
  5. _Who
    Replies:
    7
    Views:
    2,630
Loading...

Share This Page