Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set cookies in Internet Explorer

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 creates, 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");
like image 201
HyLian Avatar asked Jan 05 '11 14:01

HyLian


People also ask

How do I set cookies in Internet Explorer?

Settings > View advanced settings. Scroll down to Cookies, and select Don't block cookies Internet Explorer In Internet Explorer, in the menu bar, select Tools > Internet options > Privacy > Advanced. Select Accept or Prompt under First-party Cookies, and Accept or Prompt under Third-party Cookies. Select OK.

Where do I find cookies in Internet Explorer?

In Internet Explorer, select the Tools button, and then select Internet options. Select the Privacy tab, and under Settings, select Advanced and choose whether you want to accept, block, or be prompted for first-party and third-party cookies.

What is cookies in API?

A cookie is a piece of data that a server sends in the HTTP response. The client (optionally) stores the cookie and returns it on subsequent requests. This allows the client and server to share state. To set a cookie, the server includes a Set-Cookie header in the response.


1 Answers

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.

like image 161
i_am_jorf Avatar answered Oct 16 '22 04:10

i_am_jorf