none
WebBrowser and cookies RRS feed

  • Question

  • Hello, I have an application in which the user can open a new window in the web browser, however, the cookies of the original window don´t seem to resend the cookies and the authentication then is over. I´m using the .net WebBrowser component and this is the code where I implement the NewWindow event:

    Declaration of the net WebBrowser: (I get the underlaying activex object to use the NewWindow2 event)

    WebBrowser _webBrowser = new WebBrowser();
    SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)_webBrowser.ActiveXInstance;
    wb.RegisterAsBrowser = true;
    wb.NewWindow2 += new SHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(wb_NewWindow2);


    Implementation of the NewWindow2 event:

    void wb_NewWindow2(ref object ppDisp, ref bool Cancel)
            {
                try
                {
                    WebBrowser wb = new WebBrowser();
                    ppDisp = (SHDocVw.IWebBrowser2)wb.ActiveXInstance;
                    ((SHDocVw.IWebBrowser2)wb.ActiveXInstance).RegisterAsBrowser = true;
                    wb.Visible = true;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }


    Ok, this does not work at all. I cannot explain it. I tried with many different interfaces and it does not work either. Please, some help would be nice.
    Note: I´ve already read the related posts and the didn´t help me.


    Friday, June 12, 2009 12:07 PM

Answers

  • Hi,

    I don't think this is achievable as your webbrowser and the new window will open two URL, the cookie and user authentication will serve just for one website session. Open two website mean open two different sessions.

    Webbrowser is just for viewing the url content, to send cookie or transfer user authentication information will be handled by asp.net within one session.

    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Friday, June 19, 2009 2:04 AM
    Wednesday, June 17, 2009 9:02 AM