InternetExplorer.Application对象和cookie容器 [英] InternetExplorer.Application object and cookie container

查看:573
本文介绍了InternetExplorer.Application对象和cookie容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在VB.NET中编写的以下控制台应用程序:

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

此程式使用 InternetExplorer.Application 自动化对象启动IE窗口并导航给定的URL。我遇到的问题是,即使我启动我的应用程序的多个实例,使用此方法创建的IE窗口都共享相同的cookie容器。是否有任何参数我可以使用指定为每个窗口创建不同的cookie容器?

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?

这是我用来测试cookie的网页:

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>


推荐答案

关于 CreateObject InternetExplorer.Application)您创建一个Internet Explorer的实例,并且您的程序的所有实例通过这一个进程进行通信。

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.

您可以尝试在您的应用程式中使用 WebBrowser 控制(请参阅 http://msdn.microsoft.com/en-us /library/3s8ys666.aspx )。您可以在 http://msdn.microsoft.com/ en-us / library / aa752044(VS.85).aspx 信息比较两种方式。如果您在应用程序中使用 WebBrowser 控制,您的应用程序的所有实例将有自己的一组cookie,但每个进程只有一组cookie,而不依赖于 WebBrowser 控制。

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.

在任何过程中,您可以随时清除cookie, p>

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);

(请参阅 http://support.microsoft.com/kb/195192/en ),再次显示Cookie持有的性质。

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

这篇关于InternetExplorer.Application对象和cookie容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆