CookieContainer and CookieCollection

G

Guest

I have a CookieContainer full of Cookies.

I want to loop through the CookieContainer to display the cookies?

How can I do this.

I know how to loop through a CookieCollection and display the cookies.

How can I turn a CookieContainer into a CookieCollection?

I tried something like this:
Public Sub f_DisplayCookies(ByVal cc As Net.CookieContainer)
Dim cookie As Net.Cookie
Dim ccCookieCollection As Net.CookieCollection = CType(cc,
Net.CookieCollection)
For Each cookie In ccCookieCollection
'Display Cookie
next
End Sub

But I get an error message saying that I can not use CType to change the
data type from a CookieContainer to a CookieCollection?

Any insight would be greatly appreciated.

TIA.
 
A

Anthony Jones

Paul said:
I have a CookieContainer full of Cookies.

I want to loop through the CookieContainer to display the cookies?

How can I do this.

I know how to loop through a CookieCollection and display the cookies.

How can I turn a CookieContainer into a CookieCollection?

I tried something like this:
Public Sub f_DisplayCookies(ByVal cc As Net.CookieContainer)
Dim cookie As Net.Cookie
Dim ccCookieCollection As Net.CookieCollection = CType(cc,
Net.CookieCollection)
For Each cookie In ccCookieCollection
'Display Cookie
next
End Sub

But I get an error message saying that I can not use CType to change the
data type from a CookieContainer to a CookieCollection?

A CookieCollection is the set of cookies that have been assigned to a
specific URI. The CookieContainer contains multiple CookieCollections keyed
by the URI.

To enumerate cookies for a URI you must first retrieve a CookieCollection
from the CookieContainer using GetCookies.

You can not enumerate all cookies in the container you can only enumerate
cookies for a specific URI.
 
G

Guest

Thank you for your assistance.

I do understand the connection to the URI.

But lets say that I store a CookieCollection in an application variable. And
3 days later, I want to loop through the cookies in the type-defined
application variable (i.e. a CookieContainer). After three days, I don't
really have a URI, do I?

Or do I just reference the application variable as the URI?

TIA.
 
A

Anthony Jones

Paul said:
Thank you for your assistance.

I do understand the connection to the URI.

But lets say that I store a CookieCollection in an application variable. And
3 days later, I want to loop through the cookies in the type-defined
application variable (i.e. a CookieContainer). After three days, I don't
really have a URI, do I?

Or do I just reference the application variable as the URI?


I'm afraid you've lost me there. If you have maintained a reference to
CookieCollection in an application variable that variable must have a name,
why not just retrieve the collection using the name?
 
G

Guest

Because the application variable is NOT a CookieCollection (i.e. a
collection) - it is a CookieContainer, which means I must have a URI to
access the individual cookies.

But how can I have an URI if it is in a application variable?
 

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