This is actually an issue with the CookieContainer in .NET 3.5 which Microsoft are not going to fix, but is fixed in .NET 4+.
See https://connect.microsoft.com/VisualStudio/feedback/details/541197/cookiecontainer-domain-handling-issue-net-2-0-3-5.
There is a work around which I have added to my "modified" version of this code.
(We're stuck with .NET 3.5 due to SQL Server Report Services.)
This is actually an issue with the CookieContainer in .NET 3.5 which Microsoft are not going to fix, but is fixed in .NET 4+.
See https://connect.microsoft.com/VisualStudio/feedback/details/541197/cookiecontainer-domain-handling-issue-net-2-0-3-5.
There is a work around which I have added to my "modified" version of this code.
(We're stuck with .NET 3.5 due to SQL Server Report Services.)