Looking for cookies?

  • Thread starter Thread starter brett
  • Start date Start date
B

brett

I'm doing this to get a listing of cookies:
HttpContext.Current.Request.Cookies.AllKeys

and
HttpContext.Current.Request.Cookies.AllKeys.ToString()

However, that only gives:

System.String[]

How can I get a listing of cookies sent by the client?

Thanks,
Brett
 
Just browse the array using a for or foreach loop. Here you are asking to
produce a string representation for the whole array so its just outputs its
type...
 
Thanks. That worked:
string allCookie = "";
foreach(string cookie in HttpContext.Current.Request.Cookies)
allCookie += "\r\n" + cookie;

My site sets a cookie but I don't see it in the email I'm sending from
the site, which uses the above code. The only cookie I see is
ASP.NET_SessionId. I checked in IE privacy to see if the cookie had
been blocked/allowed. The site isn't listed there at all. I checked
under Tools | Internet Options | Settings | View Files for the
particular cookie. I have only five text files (cookies) listed and my
site isn't one of them.

Any ideas how I can get the cookie set on my site to see if it outputs
in the loop?

Thanks,
Brett
 
You need to first write cookie when responding first to the user request.
something like this :-

HttpCookie MyCookie = new HttpCookie("LastVisit");
DateTime now = DateTime.Now;

MyCookie.Value = now.ToString();
MyCookie.Expires = now.AddHours(1);

Response.Cookies.Add(MyCookie);
 
The cookie is actually set by a counter, which is a link in javascript
code to a JS file. I'm not setting the cookie. Is that something I
won't have access to? I guess that gets into extracting cookies from a
site other than my own, which is probably not allowed.

Thanks,
Brett
 

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

Back
Top