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

查看:55
本文介绍了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 的实例并且你的程序的所有实例通过这一过程.Cookie 将在每个进程中保存.

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

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天全站免登陆