Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WebBrowser在新选项卡页上设置cookie或会话_C#_.net_Session_Cookies_Browser - Fatal编程技术网

C# WebBrowser在新选项卡页上设置cookie或会话

C# WebBrowser在新选项卡页上设置cookie或会话,c#,.net,session,cookies,browser,C#,.net,Session,Cookies,Browser,我想重新创建一个具有选项卡功能、弹出块和重定向到新选项卡的web浏览器。 以下是我能够做到的: firstTabWebBrowser.Navigate("www.site-with-popup.com"); //inizializa my broeser navigation //... (firstTabWebBrowser.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += new SHDocVw.DWebBrowserEvents2

我想重新创建一个具有选项卡功能、弹出块和重定向到新选项卡的web浏览器。 以下是我能够做到的:

firstTabWebBrowser.Navigate("www.site-with-popup.com"); //inizializa my broeser navigation

//...

(firstTabWebBrowser.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(Browser_NewWindow3); //new window 3 event    

//...

private void Browser_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
{

Cancel = true; //block a new IE window to be opened

TabPage addedTabPage = new TabPage("redirected tab"); //create new tab
tabControl_webBrowsers.TabPages.Add(addedTabPage); //add new tab to the TabControl
System.Windows.Forms.WebBrowser newTabWebBrowser = new System.Windows.Forms.WebBrowser() //create new WebBrowser inside the new tab
{
   Parent = addedTabPage,
   Dock = DockStyle.Fill
};

System.Windows.Forms.WebBrowser actualWebBrowser = (System.Windows.Forms.WebBrowser)tabControl_webBrowsers.SelectedTab.GetChildAtPoint(new Point(10, 10)); //the only way I've found to select the actual webBrowser
ppDisp = actualWebBrowser.ActiveXInstance; //try to pass actual browser reference to the new browser, but I can't notice any difference without this line

newTabWebBrowser.Navigate(bstrUrl); //navigate to the popup destination url

(newTabWebBrowser.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(Browser_NewWindow3); //attach this function to the new browser            

}      

尝试

我在一些网站上进行了测试,新选项卡上的弹出重定向可以正常工作,但新生成的webBrowser似乎丢失了会话身份验证。我发现前面的问题似乎与我的问题很接近,但根据答案,问题依然存在。 因此,我想这可能是由于原始webBrowser的cookies,我可以通过actualWebBrowser.Document.Cookie访问它,但我无法访问新浏览器

  • 我尝试了
    newTabWebBrowser.ActiveXInstance=actualWebBrowser.ActiveXInstance
    而不是
    ppDisp=actualWebBrowser.ActiveXInstance
    这听起来很糟糕,无法编译,因为newTabWebBrowser.ActiveXInstance是只读的
  • newTabWebBrowser.Document.Cookie=actualWebBrowser.Document.Cookie生成一个错误,该错误不会阻止应用程序,但会跳过我的
    浏览器\u NewWindow3()
    功能
  • 我还发现了
    InternetSetCookie(url,cookie)必须由[DllImport(“wininet.dll”,CharSet=CharSet.Auto,SetLastError=true)]静态外部bool InternetSetCookie(字符串Url,字符串Cookie)声明不幸的是,我不能使用这些,可能我错过了一些语句

问题

如何强制新浏览器(位于“新建”选项卡内)记住其“父”会话/登录信息

(甚至没有人试图回答。请注意我是否以错误的方式发布了此问题,或者如果存在另一个c#专用论坛,我可以在那里发布我的问题)


方案: