471,350 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Strange behaviour with GetCookies()

Hi,

I have been working on some code that interacts with a website using
the HTTPRequest object and I have come across an issue where cookies
behave differently in the dotnet framework to the way they behave in
Internet Explorer and FireFox.
If I visit the website in question, it returns a cookie with a
leading
full stop (or period for our US cousins) in the domain part of the
cookie - for example: ".www.mydomain.com".
The problem with this is that IE will return that cookie for any
subsequent requests to www.mydomain.com whereas a call to the dotnet
framework's CookieContainer.GetCookies("http://www.mydomain.com")
will
not return that cookie. Does anyone have any experience of the issue
or have any suggestions for a workaround (I do not have access to the
source code for the website and therefore I can't simply remove the
leading ".")
I have included a C# snippet of code which demonstrates the problem
below:
Uri thisUri = new Uri("http://www.mydomain.com/somepage.aspx");
Cookie thisCookie = new Cookie("SessionID",
"ABCDEFG1234567890", "/", ".www.mydomain.com");

CookieContainer myCookieContainer = new CookieContainer();
CookieCollection myCookieCollection = new CookieCollection();

myCookieContainer.Add(thisCookie);

myCookieCollection = myCookieContainer.GetCookies(new Uri("http://
www.mydomain.com"));
string sCookie = "";
foreach (Cookie tempCookie in myCookieCollection)
{
sCookie += tempCookie.Name;
}
Regards

Bertie.
Jun 27 '08 #1
0 1080

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Paul Drummond | last post: by
3 posts views Thread by Bruno van Dooren | last post: by
3 posts views Thread by Sebastian C. | last post: by
6 posts views Thread by Edd Dawson | last post: by
8 posts views Thread by Dox33 | last post: by
20 posts views Thread by Pilcrow | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.