sending Cookies from the client side

A

andrewsc

Hi,

I'm writing a client-side Web console application, which needs to
navigate from page to page. When I access the first page, the server
sends me some cookies, which I need to return in the second request,
etc. Unless the cookies apply to a different domain.

In client-side code, what is the best way of returning cookies to the
server ?

I'm looking at the CookieContainer property of HttpWebRequest. The
documentation does not specify whether the request object is able to
filter for the cookies which apply to the URI. Would be nice to have
a single CookieContainer object, with each request picking up its own
cookies. After all, the request known the URI, so it should be able
to pick up the relevant subset.

The documentation only says about the CookieContainer property: "Gets
or sets the cookies associated with the request". It does not say
whether the request actually sends any, all, or none of the cookies
in the container. Any ideas ?

I have seen explicit filtering done in
http://www.dotnetboards.com/viewtopic.php?t=7453&view=next

I hoped it wasn't necessary for my own code to filter cookies by their
URI. On the other hand, it could be worse, if I had to add the
"Cookie" headers myself to the request.

Andrew
 
S

Scott M.

You don't return a cookie to the server. You simply write to it and then
that data is available to any page (client or server) that wants the data.

From the client, look at the document.cookies[] array.


andrewsc said:
Hi,

I'm writing a client-side Web console application, which needs to
navigate from page to page. When I access the first page, the server
sends me some cookies, which I need to return in the second request,
etc. Unless the cookies apply to a different domain.

In client-side code, what is the best way of returning cookies to the
server ?

I'm looking at the CookieContainer property of HttpWebRequest. The
documentation does not specify whether the request object is able to
filter for the cookies which apply to the URI. Would be nice to have
a single CookieContainer object, with each request picking up its own
cookies. After all, the request known the URI, so it should be able
to pick up the relevant subset.

The documentation only says about the CookieContainer property: "Gets
or sets the cookies associated with the request". It does not say
whether the request actually sends any, all, or none of the cookies
in the container. Any ideas ?

I have seen explicit filtering done in
http://www.dotnetboards.com/viewtopic.php?t=7453&view=next

I hoped it wasn't necessary for my own code to filter cookies by their
URI. On the other hand, it could be worse, if I had to add the
"Cookie" headers myself to the request.

Andrew
 
J

Jochen Kalmbach

Scott said:
You don't return a cookie to the server. You simply write to it and
then that data is available to any page (client or server) that wants
the data.

From the HTTP-Point of view your answer is not correct.

In ever GET/POST from the client to the server the cookie(s) are sent via
the HTTP-Request.

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
 

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

Top