I'll start by explaining the scenario:
I have a IE browser in the computer A. Inside the IE I have a plugin so I can access to the Document Object, so I can grab the cookie in a given time.
I want to transfer that cookie to a new browser in a different computer B.
In order to start the browser in the new computer B I use the InternetExplorer object, I can control the browser using the object instance, but I don't know how to "inject" the cookie of the first computer A to the newly created IE Browser.
I have tried two ways.
First, I tried to write the cookie before starting the browser using WinInet API InternetSetCookie.
And Secondly, I tried to intercept the BeforeNavigate2 Event and set the cookie in the header of the HTTP request.
But none of those have worked :(
Is It possible to set a cookie in a new Internet Explorer before navigate to a website and therefore be able to maintain the sesion the user had in his previous computer?
Thanks :)
UPDATE: I'm still having this issue and did some other investigations using wireshark.
In the case of BeforeNavigate2, the IExplore simply ignore the "Cookie:" value in the header.
In the case of InternetSetCookie, it seems it's working properly. It create the same file the regular IExplore navigation c开发者_StackOverflow社区reates, but when you go to that page, the IE ignores the file which contains the cookie.
The code i'm using to write the cookie is:
string cookie = "COOKIEVALUES";
InternetSetCookie("http://www.facebook.com/", "", cookie+";expires=Sat, 08-Jan-2014 00:00:00 GMT");
InternetSetCookie() should be the proper way of doing it. Have you verified you're setting the correct values? Are you using a canonicalized url? Are you specifying an expiration date? Getting the URL wrong (I'm not sure if things such as trailing /'s matter or not) will have obvious consequences, and if you don't set an expiration date the cookie is held in memory for the current process only.
First, try to use a tool like IEdebugBar - it will show you all sent and received headers in a clean way.
Second, have you verified that the cooky doesn't get send to the server? Since it seems you are trying to 'steal' a facebook session,I would assume that facebook will ignore a session-cookie coming from a browser with a different IP, UserAgent etc. Have you taken this into consideration?
http://social.msdn.microsoft.com/Forums/ar/ieextensiondevelopment/thread/d46f0797-5ddb-40c0-af71-2178fa019da8
Check this text
After comparing the 2 environments where the code and works and where it doesn't I found that on the computer where the code doesn't work I have a directory Cookies under my user account and I see the file with the cookies which I can't erase.
On another machine where the code works I don't have a directory Cookies under the user logged in even though I do see the file under Temporary Internet Files directory.
精彩评论