2

Is there any way to pass cookie to IWebBrowser's Navigate method.

As far as I can see neither passing Cookie header in headers nor InternetSetCookie/InternetSetCookieEx works with IE11.

The only working method I found is to set cookie via put_cookie of IHTMLDocument2, but for that you have to load page first.

Is there any way to pass cookie to first call of Navigate?

elevener
  • 1,097
  • 7
  • 20

1 Answers1

1

You could try IESetProtectedModeCookie if you are interacting with low-integrity browser controls. This still has limitations as noted in this cookie FAQ:

IE10+ on Windows 8+ introduced Enhanced Protected Mode which uses AppContainers (rather than Integrity Levels) for isolation. EPM does not offer an API for interacting with cookies; IESetProtectedModeCookie will not set the cookie inside an AppContainer.

Creating AppContainers is not documented so I assume your process is not running in a AppContainer?

This newsgroup thread confirms that you cannot set a cookie in the headers:

In case anybody is interested, I went through Microsoft support to find out more about this. Their answer: what I want to do is not supported. The 'headers' argument to Navigate/Navigate2 CANNOT be used to set cookies.

I'm guessing that refreshing the page after put_cookie is unacceptable?

Anders
  • 97,548
  • 12
  • 110
  • 164
  • Your link states that IESetProtectedModeCookie - Calls the standard InternetSetCookieEx, so I don't think that'll make a difference to direct call. – elevener Feb 27 '17 at 15:51
  • > I'm guessing that refreshing the page after put_cookie is unacceptable? Right now I do exactly that, but that's undesirable. – elevener Feb 27 '17 at 15:52
  • IESetProtectedModeCookie calls InternetSetCookieEx in the right context. You have not provided any information about your application so I don't know if it is relevant but on Vista+ IE has two storage locations for cookies. – Anders Feb 27 '17 at 16:45
  • I simply create instance of IE via CoCreateInstance and use Navigate to go to page via automation. And I want to set cookie in http request passed by Navigate. IESetProtectedModeCookie doesn't help either. – elevener Feb 28 '17 at 11:33