Results 1 to 8 of 8

Thread: WebBrowser Control loses session state . . . RESOLVED (well, kind of . . .)

  1. #1

    Thread Starter
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857

    WebBrowser Control loses session state . . . RESOLVED (well, kind of . . .)

    Hey guys (and gals),

    Haven't posted in a bit, but I really need your help with something. I have an application that we are planning to use to host our Oracle portal page. The application has a WebBrowser control that navigates to our portal page where the user logs in. When the user clicks on a link in the WebBrowser control that opens and external page, they have to log in again. Basically the new link opens a new IE window in a new process thread and the WebBrowser control does not pass the session state to the new IE instance.

    MSDN recommends creating a new instance of a form that has a WebBrowser control to open the newly spawned IE link request like so . . .

    VB Code:
    1. Private Sub wbPortal_NewWindow2(ppDisp As Object, Cancel As Boolean)
    2. '    ppDisp: A pointer to the IDispatch interface of a WebBrowser
    3.     'or InternetExplorer object. You set this pointer equal to the
    4.     'IDispatch interface of a new or existing WebBrowser or
    5.     'InternetExplorer object.
    6.     Dim frmWB As frmBrowser
    7.     Set frmWB = New frmBrowser
    8.    
    9.     With frmWB
    10.         .WebBrowser1.RegisterAsBrowser = True
    11.         Set ppDisp = .WebBrowser1.object
    12.         .Visible = True
    13.     End With
    14.     Set frmWB = Nothing
    15. End Sub

    This works, but not so well for specifically sized windows opened through javascript instead of links. I really want the new window to open in IE but maintain session state. I have seen code posted, but it simply doesn't work . . .

    VB Code:
    1. Dim ie As InternetExplorer
    2.  
    3. Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    4.     Set ie = Nothing
    5.     Set ie = New InternetExplorer
    6.     With ie
    7.         .RegisterAsBrowser = True
    8.         Set ppDisp = ie.Application
    9.         ppDisp.Visible = True
    10.     End With
    11.    
    12. End Sub

    This will open the new IE window and it does handle popups correctly, but session state is lost and the user needs to re-login on the new page.

    MSDN states . . .

    ppDisp: A pointer to the IDispatch interface of a WebBrowser
    or InternetExplorer object. You set this pointer equal to the
    IDispatch interface of a new or existing WebBrowser or
    InternetExplorer object.
    which seems like the key to me, but I just came seem to put all the pieces together.

    HELP!

    Thanks in advance . . .
    Last edited by Armbruster; Aug 26th, 2004 at 06:11 PM.
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  2. #2
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    Hi Armbruster,

    I've never experienced this problem and I don't know if the session can remain through various browser instances.

    However, if you can't get those sessions to work, this might solve your problem. You can dynamically fill in the login form and redirect to the correct page programmatically. So the first time the user logs in (when the first session is started) you read out the username and password and store them in variables. Then every time the login page appears, automatically fill in the name and password and submit.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  3. #3

    Thread Starter
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    Vader,

    I appreciate the idea. Unforunately, we are using this at remote locations on a WAN with a rather small pipeline (slow!), so re-submitting each time would cause a noticable delay.

    I have to believe there has to be a way to do this!

    If anyone wants to see the error in action:

    This works because IE saves the session state and the new IE window is opened in the same IE process (unless you have changed this setting in your registry)
    1) open internet explorer
    2) navigate webmail site (hotmail, msn, etc.)
    3) login and navigate to one of your mail messages
    4) right-click on one of your messages and select open in a new window
    5) you should be able to see your mail message in the new window

    This fails because the newly spawned IE opens in a seperate process and the browser control does not pass the session state to the new IE instance.
    1) add a browser control to a form
    2) navigate the browser to a webmail site (hotmail, msn, etc.)
    3) login and navigate to one of your mail messages
    4) right-click on one of your messages and select open in a new window
    5) your new window will ask you to log in because your credentials are lost!
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  4. #4
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    weird this works to me well

    EDIT: hehehe you know why ur session is lost...
    Cookies ...let me see if i can fix this
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

  5. #5
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    Ok and this fixes that

    VB Code:
    1. Private Sub MakeBrowser(ByRef ppDisp As Object)
    2.  
    3.   Dim frmWB As frmWeb
    4.   Set frmWB = New frmWeb
    5.  
    6.   frmWB.WB.RegisterAsBrowser = True
    7.   Set ppDisp = frmWB.WB.Object
    8.   frmWB.Visible = True
    9.  
    10. End Sub
    11.  
    12. Private Sub WB_NewWindow2(ppDisp As Object, Cancel As Boolean)
    13.   MakeBrowser ppDisp
    14. End Sub

    That should work like a charm tested on yahoo,hotmail and worked...no lost session
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

  6. #6

    Thread Starter
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    EJ12N, I said in my original post that I got it to work by doing this:

    MSDN recommends creating a new instance of a form that has a WebBrowser control to open the newly spawned IE link request like so . . .


    visual basic code:--------------------------------------------------------------------------------
    Private Sub wbPortal_NewWindow2(ppDisp As Object, Cancel As Boolean)
    ' ppDisp: A pointer to the IDispatch interface of a WebBrowser
    'or InternetExplorer object. You set this pointer equal to the
    'IDispatch interface of a new or existing WebBrowser or
    'InternetExplorer object.
    Dim frmWB As frmBrowser
    Set frmWB = New frmBrowser

    With frmWB
    .WebBrowser1.RegisterAsBrowser = True
    Set ppDisp = .WebBrowser1.object
    .Visible = True
    End With
    Set frmWB = Nothing
    End Sub
    --------------------------------------------------------------------------------


    This works, but not so well for specifically sized windows opened through javascript instead of links. I really want the new window to open in IE but maintain session state.
    But I don't want to open each new window in a browser form from my application because it doesn't do so well with specifically sized popups created from javascript. I want each new window to open up in IE but maintain the session state from the browser control.
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  7. #7
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    I want each new window to open up in IE but maintain the session state from the browser control.
    That i dont know
    pardon me for code above
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

  8. #8

    Thread Starter
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    EJ12N,

    No need to ask for pardon, I certainly appreciate the responses!

    I've to decided just to change my application to host Internet Explorer instead of the WebBrowser control and that should take care of things.
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width