InternetExplorer.Application object and cookie container

I have the following console application written in VB.NET:

Sub Main() Dim ie As Object = CreateObject("InternetExplorer.Application") ie.Visible = True ie.Navigate2("http://localhost:4631/Default.aspx") End Sub 

This program uses the InternetExplorer.Application automation object to launch an IE window and navigate to a given URL. The problem I am facing is that even if I run multiple instances of my application, IE windows created using this method all use the same cookie container. Is there any parameter that I could use, indicating that a different cookie container is created for each window?

This is the webpage I used to check cookies:

 <%@ Page Language="C#" AutoEventWireup="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { // Store something into the session in order to create the cookie Session["foo"] "bar"; Response.Write(Session.SessionID); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <body> <form id="form1" runat="server"></form> </body> </html> 
+4
source share
1 answer

In relation to CreateObject("InternetExplorer.Application") you create an instance of Internet Explorer, and all instances of your program communicate through this single process. Cookies will be held in the process .

Instead, you can try using WebBrowser in your application (see http://msdn.microsoft.com/en-us/library/3s8ys666.aspx ). You will find information at http://msdn.microsoft.com/en-us/library/aa752044(VS.85).aspx that can be compared in two ways. If you use the WebBrowser in your application, all instances of your application will have their own set of cookies, but only one set of cookies for each process depends on the number of WebBrowser controls in your application.

Inside any process, you can clear the cookie at any time regarding the next call.

 InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0); 

(see http://support.microsoft.com/kb/195192/en ), which once again shows the nature of cookies.

+2
source

Source: https://habr.com/ru/post/907150/


All Articles