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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop through cookies not returning any results

Status
Not open for further replies.

Ranvier

Programmer
Jun 17, 2004
73
GB
Hello All,

Using asp.net

I am trying to retrieve a cookie that is being set manually on the IIS server when the page loads. However I cannot seem to get the value. When I use firefox debugger all the cookies are showing correctly, but when I use a CookieContainer to loop through all the cookies I cannot get any results excpet from this:

24/11/2009 08:09:00 Cookie:guide.opendns.com
24/11/2009 08:09:00 Cookie:t
24/11/2009 08:09:00 Cookie:/
24/11/2009 08:09:00 Cookie:x-0
24/11/2009 08:09:00 Cookie:

My code is below (the l.wl just prints the line). Does anyone know how to retrieve the cookies?

//-------------------------------

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(" request.CookieContainer = new CookieContainer();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

foreach (Cookie cook in response.Cookies)
{
l.wl("Cookie:" + cook.Domain);
l.wl("Cookie:" + cook.Name);
l.wl("Cookie:" + cook.Path);
l.wl("Cookie:" + cook.Value);
l.wl("Cookie:" + cook.CommentUri);
}

//-------------------------------

Thanks in advance
 
Thanks, I used the code from the link and t work but it again doesnt return what I expect

24/11/2009 19:50:37 MyCookie Cookie: ASP.NET_SessionId
24/11/2009 19:50:37 MyCookie Expires: 01/01/0001 00:00:00
24/11/2009 19:50:37 MyCookie Secure:False
24/11/2009 19:50:37 MyCookie loop2 cookie0:
24/11/2009 19:50:37 passGuid = 15878366123895987018666568
24/11/2009 19:50:40 MyCookie Cookie: ASP.NET_SessionId
24/11/2009 19:50:40 MyCookie Expires: 01/01/0001 00:00:00
24/11/2009 19:50:40 MyCookie Secure:False
24/11/2009 19:50:40 MyCookie loop2 cookie0:

again it doesnt seem to be returning any cookies - what am i doing wrong?
 
My aim is to retrieve a cookie that is being set server side so I ca use the value of the cookie as part of my validation process.

The cookie is being set in an .inc file and is:

Response.Cookies("sessionId") = sessionId;

When I run my app I am expecting to get this cookie, I have tried what I think is correct but I cannot seem to get the content of the cookie.

Have tried

Request.Cookies["sessionId"].Value

Session.SessionID

and also looping through the cookies as above but nothing is returned.

The page is opened by many users at different times.

Thanks
 
How are you using a .inc file? They are not used anymore in .NET although I guess you could. I suspect that the cookies are not being set initially.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top