473,850 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CookieContainer and CookieCollectio n

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 CookieCollectio n and display the cookies.

How can I turn a CookieContainer into a CookieCollectio n?

I tried something like this:
Public Sub f_DisplayCookie s(ByVal cc As Net.CookieConta iner)
Dim cookie As Net.Cookie
Dim ccCookieCollect ion As Net.CookieColle ction = CType(cc,
Net.CookieColle ction)
For Each cookie In ccCookieCollect ion
'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 CookieCollectio n?

Any insight would be greatly appreciated.

TIA.
Nov 12 '07 #1
4 10167
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:8C******** *************** ***********@mic rosoft.com...
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 CookieCollectio n and display the cookies.

How can I turn a CookieContainer into a CookieCollectio n?

I tried something like this:
Public Sub f_DisplayCookie s(ByVal cc As Net.CookieConta iner)
Dim cookie As Net.Cookie
Dim ccCookieCollect ion As Net.CookieColle ction = CType(cc,
Net.CookieColle ction)
For Each cookie In ccCookieCollect ion
'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 CookieCollectio n?
A CookieCollectio n is the set of cookies that have been assigned to a
specific URI. The CookieContainer contains multiple CookieCollectio ns keyed
by the URI.

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

You can not enumerate all cookies in the container you can only enumerate
cookies for a specific URI.
--
Anthony Jones - MVP ASP/ASP.NET
Nov 13 '07 #2
Thank you for your assistance.

I do understand the connection to the URI.

But lets say that I store a CookieCollectio n 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.

"Anthony Jones" wrote:
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:8C******** *************** ***********@mic rosoft.com...
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 CookieCollectio n and display the cookies.

How can I turn a CookieContainer into a CookieCollectio n?

I tried something like this:
Public Sub f_DisplayCookie s(ByVal cc As Net.CookieConta iner)
Dim cookie As Net.Cookie
Dim ccCookieCollect ion As Net.CookieColle ction = CType(cc,
Net.CookieColle ction)
For Each cookie In ccCookieCollect ion
'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 CookieCollectio n?

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

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

You can not enumerate all cookies in the container you can only enumerate
cookies for a specific URI.
--
Anthony Jones - MVP ASP/ASP.NET
Nov 13 '07 #3
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:84******** *************** ***********@mic rosoft.com...
Thank you for your assistance.

I do understand the connection to the URI.

But lets say that I store a CookieCollectio n 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
CookieCollectio n in an application variable that variable must have a name,
why not just retrieve the collection using the name?
--
Anthony Jones - MVP ASP/ASP.NET
Nov 13 '07 #4
Because the application variable is NOT a CookieCollectio n (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?

"Anthony Jones" wrote:
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:84******** *************** ***********@mic rosoft.com...
Thank you for your assistance.

I do understand the connection to the URI.

But lets say that I store a CookieCollectio n 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
CookieCollectio n in an application variable that variable must have a name,
why not just retrieve the collection using the name?
--
Anthony Jones - MVP ASP/ASP.NET
Nov 13 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2771
by: Arne Schittenhelm | last post by:
Hello, I try to figure out if there is a way to read the local cookies with CookieContainer or another .net cookie class. If I use a filename as URI I get a System.UriFormatException or System.InvalidCastException. Any ideas?
0
997
by: Noel Austin | last post by:
I've run into a problem working with the CookieContainer and was wondering if anyone else has noticed this. The CookieContainer reorders it's cookies. When you send it back to the server using the HttpWebRequest object, the cookies may not be in the same order that they were loaded into the CookieContainer. I was able to verify this with a network sniffer and it's had me scratching my head ever since. Unfortunatly the web site I was...
1
4652
by: guyhey | last post by:
I am accessing a site that passes the following headers: Set-Cookie: ASP.NET_SessionId=pwdciy45i0c5me45urxjfoi0; path=/ Set-Cookie: LastSessID=pwdciy45i0c5me45urxjfoi0; expires=Tue, 01-Mar-2016 20:07:11 GMT; path=/ Set-Cookie: pubAccID=04; expires=Tue, 01-Mar-2016 20:07:11 GMT; path=/ I have verified this using ieHttpHeaders When I use asp.net
4
5168
by: macro | last post by:
when I use HttpWebRequest with CookieContainer object that handles cookies, if I have this cookie header in a response: Set-Cookie: CookieName=; path=/;expires=01-Jan-1999 00:00:00 GMT the cookie is not deleted for the next request, what should be and actually done with Internet Explorer as client. is this a bug is there a solution / workaroung by manually deleting the cookie?
1
8210
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie to SMCHALLANGE=YES to allow me to obtain a session. I then iterate the cookie collection to extract the SMSESSION value. All is good (so far). This is when the sky turns grey and the rain starts to fall. I then use this SMSESSION in a web...
5
35296
by: rlueneberg | last post by:
I am totally confused. Can someone please illuminate what is going on under the hood in this piece of code from John Lewis. My main confusion is how the cookieContainer can be passed to the subsequent request if it is not assigned anywhere? So far this is what I understand: -Creates New cookieContainer CookieContainer cookieContainer = new CookieContainer();
4
6487
by: =?Utf-8?B?UGF1bA==?= | last post by:
Does anyone know how to loop through the CookieContainer to see each individual cookie item? Or is the CookieContainer just one variable with all the cookies in it? TIA.
2
7131
by: andrewschools | last post by:
Hi, I was wondering, can you send a CookieCollection to a System.Windows.Forms.WebBrowser? If so, how would I go about doing this. What I've done so far is send a POST request to a login form using HttpWebRequest. Now I want to send that CookieCollection to the System.Windows.Forms.WebBrowser so the user can see the protected page... Thanks, Andrew
0
1240
by: =?Utf-8?B?QnJpYW4=?= | last post by:
I'm not sure that this is the best forum for this question since I am not really hitting a webservice to do this, but just using http req/resp model to retrieve data. I have a website I am hitting using https protocol. I have the authorization and security working well but am having problems getting the cookiecollection in the httpwebresponse returned from the server to populate. It always has 0 cookies in the collection. Here is the raw...
0
9895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9744
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11011
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10670
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9503
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5931
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.