473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C# Application CookieContainer

Wondering if anyone had problems with the CookieContainers, I was making a program that logs onto sites, check for news and then reports back.

All cookies domain in response.cookies is marked as site.com except for one that is marked as .site.com for some reason this doesn't make it back to http://site.com when I try to check the messages page after doing the login.

If I override the WebResponse in WebClient and add a copy of that cookie without the initial dot all is well and I get my result. However this is not nice as I get extra cookies so I was wondering if anyone knew why?
Sep 8 '08 #1
1 4694
To explain further:

Expand|Select|Wrap|Line Numbers
  1. public class WebClientEx : WebClient
  2.     {
  3.         private CookieContainer cookies = new CookieContainer();
  4.  
  5.         protected override WebRequest GetWebRequest(Uri address)
  6.         {
  7.             WebRequest retVal = base.GetWebRequest(address);
  8.  
  9.             if (retVal.GetType() == typeof(HttpWebRequest))
  10.             {
  11.                 ((HttpWebRequest)retVal).CookieContainer = cookies;
  12.             }
  13.  
  14.             return retVal;
  15.         }
  16.  
  17.         protected override WebResponse GetWebResponse(WebRequest request)
  18.         {
  19.             WebResponse retVal = base.GetWebResponse(request);
  20.  
  21.             if (retVal.GetType() == typeof(HttpWebResponse))
  22.             {
  23.                 foreach (Cookie c in ((HttpWebResponse)retVal).Cookies)
  24.                 {
  25.                     if (c.Domain.StartsWith("."))
  26.                     {
  27.                         c.Domain = c.Domain.Substring(1);
  28.                         cookies.Add(c);
  29.                     }
  30.                 }
  31.             }
  32.  
  33.             return retVal;
  34.         }
  35.     }
Not sure why the stuff in GetWebResponse has to be done but without it it doesn't work to login on some sites. So I am curious if someone knows what is different in WebClient from a Browser regarding cookie handling.
Sep 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ollie | last post by:
I have an aspx page that contains a web control that contains 2 text boxes and button to submit the text. I am trying to submit text and collect the response from a console application, but it is...
0
by: Sivashankaran Vaidhyalingam | last post by:
Hi folks, I have an aspx application App A hosted in a server which is inside the intranet . I need to serve pages from this application _through_ another application App B which acts as a proxy...
0
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...
1
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...
4
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...
5
by: Jono | last post by:
Hi Everyone, Most tutorials I've seen address cookies from the server's perspective, assuming that the client (usually a browser like Internet Explorer) will manage the persistence. I am faced...
2
by: Arti | last post by:
Hi, I have a .Net application which has to communicate to Servlet on TomCat Server. I am able to send the request but it throws an exception while retrieving the response(Exception:The...
4
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.
4
by: =?Utf-8?B?UGF1bA==?= | last post by:
Does anyone know if you can store a Net.CookieContainer object in an Application variable?
4
by: =?Utf-8?B?UGF1bA==?= | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.