B
bertie.bunch
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",
"WEXC1JLZXX4JNFGS1LR6I89UP2KGF4FC0F", "/", ".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.
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",
"WEXC1JLZXX4JNFGS1LR6I89UP2KGF4FC0F", "/", ".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.