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. Advertisements

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:
    9,296
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,847
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    833
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    640
  5. mhshpk
    Replies:
    0
    Views:
    733
    mhshpk
    Jul 18, 2007
  6. Eric
    Replies:
    1
    Views:
    2,316
    Mark Fitzpatrick
    Dec 28, 2007
  7. _Who
    Replies:
    7
    Views:
    3,107
  8. Cal Who

    Response.cookies vs Request.cookies

    Cal Who, Dec 5, 2009, in forum: ASP .Net
    Replies:
    7
    Views:
    1,804
    Gregory A. Beamer
    Dec 10, 2009
Loading...