Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie Reading

Status
Not open for further replies.

Canelas

Programmer
Feb 20, 2008
46
0
0
PT
Hi everyone.

I'm trying to read a cookie inside an .aspx page but i don't seem to be getting there.

Here is my code:
try
{
HttpCookie cookie;
cookie = Request.Cookies.Get("name");
Label2.Text = cookie.Name;
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}

I've also tried:
cookie = Request.Cookies["name"];
and no luck.

Label1 gets the message:
"Object reference not set to an instance of an object."

I know the cookie exists.

Ideas anyone?
Thanks in advance.
 
use ex.ToString() instead of ex.Mesasge. this will display the entire stack trace. and where the problem is.

however, looking at your code the problem is the cookie does not exist.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I got it to work.
For some reason, the path attribute of the cookie was being set.

The cookie was being created by me in a JSP page. As i wasn't setting the path value myself, this atribute was being set automaticaly. I got it to work by setting the path to "/".

Thanks anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top