1

Problem:

I am using a .NET WebBrowser control. I am getting frustrated because on some pcs pop-up windows appear to lose the session cookie. After alot of research I think this is (almost certainly) because:

"When you click a hyperlink in an application that is hosting the WebBrowser control, a new page opens in Internet Explorer. In this scenario, the session cookie is lost, and you may have to log on again. This behavior occurs because Internet Explorer is a different process than the application process. A session cookie cannot be shared between processes."

Question

I am perfectly happy with using the I.E process, I just don't want user to continually have to login. So, Why does this only happen on some pcs? How is best to handle these problems? If I could intercept the url before the I.E process is launched I could re-login

Attempted solutions so far:

As a result I tried tried the solution mentioned here: System.Windows.Forms.WebBrowser open links in same window or new window with same session

private SHDocVw.WebBrowser_V1 Web_V1; //Interface to expose ActiveX methods

private void Form1_Load(object sender, EventArgs e)
{
    //Setup Web_V1 interface and register event handler
    Web_V1 = (SHDocVw.WebBrowser_V1)this.webBrowser1.ActiveXInstance;
    Web_V1.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler(Web_V1_NewWindow);
}

private void Web_V1_NewWindow(string URL, int Flags, string TargetFrameName, ref object PostData,string Headers, ref bool Processed)
{
    Processed = true; //Stop event from being processed
    Form1 Popup = new Form1();
    Popup.webBrowser1.Navigate(URL);
    Popup.Show();
}

Which presented me with a few new problems:

  1. I have a script error "Unable to get value of the property 'focus' object is null or undefined.
  2. The i.e security settings cause the following dialog "the webpage you are viewing is trying to close the window. Do you want..." when .close() is reached in the JS.

To solve these I tried NewWindow2 event: stackoverflow.com/a/6473442/17034 suggested by Hans Passant. This solved the above two problems, however window.close() now no longer closed the webview/form.

Whats the best approach here?

Community
  • 1
  • 1
Jon Wells
  • 4,191
  • 9
  • 40
  • 69
  • Try the NewWindow2 event instead: http://stackoverflow.com/a/6473442/17034 – Hans Passant Dec 20 '11 at 13:06
  • Hey just tried out the script, NewWindow2 is definitely the most successful approach so far. Only problem is the onClick events for the form buttons arent working. I think they both call window.close(); any Ideas? I think you should put your response as an answer, its the best source of info I found for Window2 – Jon Wells Dec 20 '11 at 13:38
  • 1
    @CrimsonChin, if Hans did that he'd have more points than Jon Skeet... – Jeremy Thompson Dec 21 '11 at 02:56
  • possible duplicate of [How do I display a popup from a WebBrowser in another window I created?](http://stackoverflow.com/questions/6470842/how-do-i-display-a-popup-from-a-webbrowser-in-another-window-i-created) – Brian Tompsett - 汤莱恩 Feb 04 '15 at 19:11

0 Answers0