Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 a given url. The problem that I encountered is that even if I launch multiple instances of my application, the IE windows that are created with this method all share the same cookie container. Is there any parameter I could use specifying that a different cookie container is created for every window?

This is the web page I used to test 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>
like image 469
Darin Dimitrov Avatar asked Feb 02 '09 12:02

Darin Dimitrov


1 Answers

With respect of CreateObject("InternetExplorer.Application") you create an instance of Internet Explorer and all instances of you program communicate through this one process. Cookies will be hold per process.

You can try to use in your application WebBrowser control instead (see http://msdn.microsoft.com/en-us/library/3s8ys666.aspx). You find in http://msdn.microsoft.com/en-us/library/aa752044(VS.85).aspx information which compare two ways. If you will use WebBrowser control in you application all instances of your application will have his own set of cookies, but only one set of cookies per process independent on the number of WebBrowser controls in your application.

Inside of any process you can any time clear the cookie with respect of following call

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

(see http://support.microsoft.com/kb/195192/en) which shows one more time the nature of cookies holding.

like image 64
Oleg Avatar answered Nov 16 '22 16:11

Oleg