J
Josh King
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
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