Click to See Complete Forum and Search --> : Cookie Retrieval


ericmkopp
July 28th, 2003, 02:28 PM
I have been unable to retreive a cookie except from the page that I created them on. Is there some special thing other than the code below to retrieve them:

This is in VB.Net, inside a page_load subroutine and inside script tags.

Response.Write(Request.Cookies("MyCookie")("Name"))

THis is done from another page. It returns nothing but a blank output. It works however, when done from the same sub as the cookie creation.

coolbiz
July 28th, 2003, 11:36 PM
Show the code that you use to set the cookie.

-Cool Bizs

ericmkopp
July 30th, 2003, 01:01 AM
for each strVariable in Response.Cookies("emkopp").Values

lbl1.Text += "<b>" & strVariable & "</b>:" & Request.Cookies("emkopp")(strVariable) & "<br>"

next

this is of course 1 line. The same code works in the page where i set the cookie. I found the cookie on my machine, so I know the set works.

coolbiz
July 30th, 2003, 07:15 AM
That cannot happened since COOKIE is set per domain name. I'd like to see the code that you use to SET the cookies (from the page the sets it) and the code to READ them in (from the page that reads it).

-Cool Bizs

ericmkopp
July 31st, 2003, 08:07 PM
sub Page_Load(S as Object, E as eventargs)
dim strVariable as string


Response.Write(Request.ServerVariables("URL")& " <BR>")
Response.Write(Request.ServerVariables("PATH_INFO") & "<BR>")
Response.Write(Request.ServerVariables("PATH_TRANSLATED")& " <BR>")
Response.Write(Request.ServerVariables("SERVER_NAME")& " <BR>")
Response.Write(Request.ServerVariables("SERVER_SOFTWARE")& " <BR>")

Response.Cookies("emkopp")("Name") = "emkopp"
Response.Cookies("emkopp")("Race") = "White"
Response.Cookies("emkopp")("Sex") = "Male"
Response.Cookies("emkopp")("Age") = "31"
Response.Cookies("emkopp")("Server") = Request.ServerVariables("SERVER_SOFTWARE")
Response.Cookies("emkopp").Expires = DateTime.Now.AddMonths(2)

for each strVariable in Response.Cookies("emkopp").Values

lbl1.Text += "<b>" & strVariable & "</b>:" & Request.Cookies("emkopp")(strVariable) & "<br>"

next

end sub

coolbiz
August 1st, 2003, 09:13 AM
So in your retrieval page, you are iterating the REQUEST.COOKIES collection right? Not the RESPONSE.COOKIES (as shown your code).

-Cool Bizs

ericmkopp
August 3rd, 2003, 05:05 PM
For my retreival on the other page, I am using the loop that is requesting and printing the values located in cookie. The only problem is that it doesnt work. The only variable that I can think is that the page is on localhost and there may be a problem with IIS and cookies if it is on the same machine.