gpt4 book ai didi

internet-explorer - InternetExplorer.Application 对象和 cookie 容器

转载 作者:行者123 更新时间:2023-12-04 08:59:35 24 4
gpt4 key购买 nike

我有以下用 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 容器吗?

这是我用来测试 cookie 的网页:
<%@ 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 .

您可以尝试在您的应用程序中使用 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 的数量。应用程序中的控件。

在任何进程内,您可以随时清除关于以下调用的 cookie

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

(参见 http://support.microsoft.com/kb/195192/en )再次展示了 cookie 持有的性质。

关于internet-explorer - InternetExplorer.Application 对象和 cookie 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/503041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com