Cookies with multiple paths

S

Shane Thomas

Hello,

I'm having difficulty handling cookies with paths other than "/". An
HttpWebRequest object returns these headers:

Date: Tue, 26 Apr 2005 21:29:39 GMT
Server: Apache/1.3.33 (Unix) PHP/4.3.10
Set-cookie: phpusid=12345; path=/; expires=Wednesday, 09-Nov-2008 23:12:40
GMT,data=deleted; expires=Mon, 26-Apr-2004 21:29:38 GMT; path=/stats;
domain=www.somesite.com,data=deleted; expires=Mon, 26-Apr-2004 21:29:38 GMT;
path=/stats; domain=www.somesite.com
X-Powered-By: PHP/4.3.10
Connection: close
Content-Type: text/html

However iterating through a cookie collection (TheResponse.Cookies =
TheRequest.CookieContainer.GetCookies(TheRequest.RequestURI)) only contains
the cookies with a path of "/".

How do I access the cookies with paths other than "/"? Can I gather them all
in one collection?

Thanks,

-shane
 
S

Shane Thomas

I'm having difficulty handling cookies with paths other than "/". An
HttpWebRequest object returns these headers:

Date: Tue, 26 Apr 2005 21:29:39 GMT
Server: Apache/1.3.33 (Unix) PHP/4.3.10
Set-cookie: phpusid=12345; path=/; expires=Wednesday, 09-Nov-2008 23:12:40
GMT,data=deleted; expires=Mon, 26-Apr-2004 21:29:38 GMT; path=/stats;
domain=www.somesite.com,data=deleted; expires=Mon, 26-Apr-2004 21:29:38
GMT; path=/stats; domain=www.somesite.com
X-Powered-By: PHP/4.3.10
Connection: close
Content-Type: text/html

However iterating through a cookie collection (TheResponse.Cookies =
TheRequest.CookieContainer.GetCookies(TheRequest.RequestURI)) only
contains the cookies with a path of "/".

How do I access the cookies with paths other than "/"? Can I gather them
all in one collection?

With a bit more investigation, only cookies in the first path (as specified
in the Set-cookie: header) are stored in the HttpWebResponse container. Once
the path changes they're lost.

I know I'm missing something simple -- googling hasn't helped and nobody's
responded so I'm obviously brain-farting but cannot see it.

Thanks for any pointers,

-shane
 
J

Juan T. Llibre

I'm a little puzzled by what you want to do.

You want to read a cookie set by Apache/1.3.33 (Unix)
running PHP/4.3.10, using HttpWebResponse, and you
want to read it with ASP.NET ?

Or, is there another reason for you to post this question here ?




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
S

Shane Thomas

You want to read a cookie set by Apache/1.3.33 (Unix)
running PHP/4.3.10, using HttpWebResponse, and you
want to read it with ASP.NET ?

Or, is there another reason for you to post this question here ?

I'm using VB.NET but thought the question was appropriate in .aspnet as
well. Perhaps this is more appropriate only on .languages.vb.

I'm collecting pages from websites that require cookies to login. Some of
these sites send multiple cookies in different paths and therein lies my
problem. I'd like all cookies in a Set-cookie: header to be in the response
object's cookie collection, regardless of path. Currently the collection
only has cookies for the first path in the header -- once the path changes
the cookies [seemingly] aren't placed in the collection.

Every time I describe the problem it feels like I'm missing a paragraph that
describes precisely why I'm having the problem. Like I'm not initializing
the cookie container properly. Or that I need to change a URI or path
somewhere. But google as I might...

Thanks,

-shane
 
J

Juan T. Llibre

Ahh, I understand a bit better now.

The crux is that, if the path is not set by the cookie,
then the cookie defaults to the main domain or "/".

You'll need a bit of cooperation from the cookie-setters in order
to insure the retrieval of the proper cookie-path at all path levels.

If a cookie has already passed domain matching, then the pathname
component of the URL is compared with the path attribute and,
if there is a match, the cookie is considered valid and is sent along
with the URL request.

The path "/foo" would match "/foobar" and "/foo/bar.html".

If a cookie path isn't programmed, you can't retrieve it.



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

Shane Thomas said:
You want to read a cookie set by Apache/1.3.33 (Unix)
running PHP/4.3.10, using HttpWebResponse, and you
want to read it with ASP.NET ?

Or, is there another reason for you to post this question here ?

I'm using VB.NET but thought the question was appropriate in .aspnet as well. Perhaps
this is more appropriate only on .languages.vb.

I'm collecting pages from websites that require cookies to login. Some of these sites
send multiple cookies in different paths and therein lies my problem. I'd like all
cookies in a Set-cookie: header to be in the response object's cookie collection,
regardless of path. Currently the collection only has cookies for the first path in the
header -- once the path changes the cookies [seemingly] aren't placed in the collection.

Every time I describe the problem it feels like I'm missing a paragraph that describes
precisely why I'm having the problem. Like I'm not initializing the cookie container
properly. Or that I need to change a URI or path somewhere. But google as I might...

Thanks,

-shane
 
S

Shane Thomas

The crux is that, if the path is not set by the cookie,
then the cookie defaults to the main domain or "/".

The header I'm receiving is:

Set-cookie: phpusid=12345; path=/; expires=Wednesday, 09-Nov-2008 23:12:40
GMT,data=deleted; expires=Mon, 26-Apr-2004 21:29:38 GMT; path=/stats;
domain=www.somesite.com,data=deleted; expires=Mon, 26-Apr-2004 21:29:38 GMT;
path=/stats; domain=www.somesite.com

The paths are explicitly set, however my response object only contains the
cookie "phpusid". The two cookies with the path set to "/stats" do not
appear in the collection. The same behavior occurs no matter what the paths
are -- the response object only contains cookies that belong to the path set
by the first cookie in the header.

Thanks again, I appreciate it.

-shane
 

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