Hi,
I just test to reply in google groups.
Replying on your email, I already studying this CookieContainer, CC
since I read this issue here last 2 weeks.
Also I have read your feedback to Microsoft, also your discussions.
Due to simply answer your feedback fixed in future release, rather
than trying to help you, I disappointed because 4.0 can't be use
widely in the recent days. Then I want to 'hack' the CookieContainer
and inspect what was goes wrong with it.
After some googling, I get this code and modify it a little bit.
public CookieCollection GetAllCookies(CookieContainer cc)
{
CookieCollection lstCookies = new CookieCollection();
Hashtable table = (Hashtable)cc.GetType().InvokeMember
("m_domainTable", System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, cc, new object[] { });
foreach (object pathList in table.Values)
{
SortedList lstCookieCol = (SortedList)pathList.GetType
().InvokeMember("m_list", System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, pathList, new object[]
{ });
foreach (CookieCollection colCookies in
lstCookieCol.Values)
foreach (Cookie c in colCookies)
{
lstCookies.Add(c);
}
}
return lstCookies;
}
This code can retrieve all stored cookie in any domain and path.
Debugging the table, lstCookieCol, colCookies and c, I have better
understanding about how CC store the cookies.
Doing some reflection to the CC also help me.
Its 'grouped' by domain (Hashtable table) and path (SortedList
lstCookieCol). The issue occur when using .Add(Cookie) method.
it different than .Add(Uri, Cookie) in the table key which is domain
name.
.Add(Cookie) - BUG here. simply use domain from the cookie as table
key. So
domain.com, .
domain.com and
sub.domain.com is three different
key.
.Add(Uri, Cookie) - it will make sure the domain have dot in the
beginning. So
domain.com and .
domain.com use one .
domain.com key.
In short, .Add(Uri, Cookie) is doing well but .Add(Cookie) is not.
Your CookieManager_New.cs is using the right one.
.SetCookie(Uri, cookieHeader) is using internal .Add()
Then I found that .GetCookies(Uri) is another BUG. It can't retrieve
cookie from "current sub domain start with dot and parent domain not
start with dot".
So since all domain key start with dot, GetCookies method can't
retrieve current sub domain. So in order to solve it domain with dot
and no dot should be in the table key as you fix it.
It work. Cookie ".
domain.com" can be retrieve for "
http://domain.com".
Also cookie "
sub.domain.com" and ".
domain.com" can be retrieve for
"
http://sub.domain.com".
I have details discuss it here, fixed based on your code:
http://dot-net-expertise.blogspot.com/2009/10/cookiecontainer-domain-handling-bug-fix.html
Yes I meant it you have solve the CookieContainer issue. I use the new
CookieManager_New.cs I download from ASProxy 5.2. I think it is your
latest one (during you discuss this cookie issue). However your latest
svn just adding BugFix_AddDotCookieDomain after
ApplyRequestToCookieContainer in AddCookiesToRequest function. Its
corrent, because httpWebRequest.CookieContainer is just change. You
need to call BugFix_AddDotCookieDomain each time CookieContainer added
a new cookie or before retrieve any cookie.
Ok, CookieContainer issue fixed. #2 is quite complicated, we discuss
later. Now #1 should be fixed. Cookie is not acting well in ASProxy.
It receive the correct cookie from web response but it send back not
the original one. It was cause cookies grouped into single www.domain.com_ASPX,
yes you can see the right cookie in the browser. but later cookies is
not ungroup to be send the original one.
I checked http traffic between ASProxy and web server by using
Fiddler2. Fiddler shows what cookie sent to the web server is not the
original one. It is www.domain.com_ASPX cookie.
Please use this Fiddler. It help so much. Think that
ApplyRequestToCookieContainer in the AddCookiesToRequest. You can see
that ApplyRequestToCookieContainer is simply get all *_ASPX cookie and
add it to the container to be sent to web server. You need to extract
the cookies inside each *_ASPX as you group it in GetCookieHeader by
using comma seperator.
I am pretty sure that I not confuse the way this CookieManager does. I
am not change the whole behavior but just add lines of code (quite
much) in a function, add functions, remove a few existing codes, and
some other move the location. I still not change the behavior and all
other classes is still remain unchange.
I have the new codes modified but it just modified for #2 and now lots
of codes there. I will give you later, still in modification. The
existing behavior still the same but just small thing I change like
cookie grouped into domain.com_ASPX to make all cookies in the same
domain including all it sub domain stored in the same CookieContainer.
We can discuss and proceed to fix this if you want.
your CookieManager class still not doing right
On Thu, Oct 8, 2009 at 3:40 AM, Salar <
salarso...@gmail.com>
wrote:
>
> Hi,
> You have an approved post in asproxy group before, so approval is not required anymore.
>
> I have created this test, which shows CookieContainer does not behave as expected.
>
http://stackoverflow.com/questions/1047669/cookiecontainer-bug
> After applying BugFix_AddDotCookieDomain the issue behavior changes!!. The new issue is about more cookies than expected for a domain.
>
> How can you find #1 issue? it is tested very much and all original cookies are sending to the back-end site. I think you are confused with client-user cookie which in embeded in xxx_ASPX cookies.
> I wonder how you fix this. maybe you've changed the whole behavior?!
> The #2 is main problem which not all cookies is send to the back-end site, because of CookieContainer.
> Also google is changing the coookie in scripts which is not known very much, but still it is encoded by __CookieGet/__CookieSet functions. And yes here is another unknown issue.
>
> Have you read this page:
>
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=478521
> The bug is accepted and fixed in .NET 4. I'm waiting to see what changes they have made to correct the CookieContainer behaviour, so I can simulate it for .NET 2, this can be a stable solution.
>
> And, there is a CookieManager_New.cs which is completely works with CookieContainer and uses its methods to store/restore cookies. But due CookieContainer but it is completely uselss. Have a look from svn:
>
http://asproxy.svn.sourceforge.net/viewvc/asproxy/SalarSoft.ASProxy/BuiltIn/DataManagement/CookieManager_New.cs?view=markup
>
> And I'll be happy to see what changes you've made in the original code. Attach the code if you want.
>
> Thanks for the attention.
> Regards
> Salar.Kh
>
>
> On Wed, Oct 7, 2009 at 9:34 PM, --:| LaNN |:-- <
nal...@gmail.com> wrote:
>>
>> Hi,
>>
>> Sorry I am confused Reply or Reply to author in this google groups. Its not friendly enough.
>>
>> Last week I post about CookieContainer here, quite long post, but the msg seems to miss when I send
>> because it not show like normally something like message sent.
>> It just Your post was successfull but my pust is not shown,
>> or it not show something like the post pending approve by administrator.
>>
>> However I just want to share that I see the bugz here...
>>
>> Last time I notice the CookieContainer have an issue. I learn how it works and what makes the bug.
>> Lastly I found that your BugFix_AddDotCookieDomain() enough to solve the CookieContainer bug. so it almost solved.
>> At the same time I can see the CookieManager is not doing the right.
>>
>> In short I notice there is 2 issue in the CookieManager:
>> #1 The domain.com_ASPX cookie is simply send to web req rather than their every single original cookie. Critical
>> #2 Each cookie should be visible to client script. So it can access and modify at document.cookie. Optional. not sure if google modify cookie in script.
>> but if #2 is not fixed, web that require access and modify cookie is not compatible.
>>
>> I am using Firebug, FireCookie, HttpFox and Fiddler2.
>>
>> I am sure this are the cause of Google login. I notice since google tell me to turn on cookie. Thats why I try to figure it out back now.
>>
>> I try to fix since I know it is not the CookieContainer issue but CookieManager not implemented correctly.
>>
>> I fix the #1. I have no luck to login. After partially fix the #2, I found that my #1 fix is not proper. After I fix the #1 again, I be able to login to google service.
>> Just test in web search, one step before gmail.
>>
>> After 2 weeks since now I can 70% login to gmail . Something like miss one more request response.
>>
>>
>>
>> On Tue, Oct 6, 2009 at 11:25 AM, Salar <
salarso...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> No i didn't got any mail or post from you!
>>>
>>> On Mon, Oct 5, 2009 at 6:12 PM, CallMeLaNN <
nal...@gmail.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> Did you receive my post before, in last few days?
>>>>
>>>> I tell about founding the cookie issue solution,
>>>> it is related to google login.
>>>>
>>>> CallMeLaNN
>> --
>> Best regards,
>> Mazlan
>>
>> "Our imagination is the only limit to what we can hope to have in the future"
>
--
Best regards,
Mazlan
"Our imagination is the only limit to what we can hope to have in the
future"