Dar*_*rov 5 cookies internet-explorer automation
我有以下用VB.NET编写的控制台应用程序:
Sub Main()
Dim ie As Object = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate2("http://localhost:4631/Default.aspx")
End Sub
Run Code Online (Sandbox Code Playgroud)
该程序使用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>
Run Code Online (Sandbox Code Playgroud)
就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中找到比较两种方式的信息。如果您将在应用程序中使用控件,则应用程序的所有实例都将拥有自己的一组 cookie,但每个进程只有一组 cookie,与应用程序中控件WebBrowser的数量无关。WebBrowser
在任何进程内,您可以随时清除以下调用的 cookie
InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);
Run Code Online (Sandbox Code Playgroud)
(请参阅http://support.microsoft.com/kb/195192/en),这再次显示了 cookie 保存的性质。
| 归档时间: |
|
| 查看次数: |
5960 次 |
| 最近记录: |