Help with cookies

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Cookies during error handling 1
Cookies 1
Cookies 1
Cookies 3
Clearing cookies 2
Cookies ... monster. Please help 3
Help on cookies ? 4
Cookies Count 2

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top