|
-
Aug 26th, 2004, 08:02 AM
#1
Thread Starter
Fanatic Member
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:
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. I have seen code posted, but it simply doesn't work . . .
VB Code:
Dim ie As InternetExplorer
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Set ie = Nothing
Set ie = New InternetExplorer
With ie
.RegisterAsBrowser = True
Set ppDisp = ie.Application
ppDisp.Visible = True
End With
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!
-
Aug 26th, 2004, 09:27 AM
#2
Fanatic Member
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
-
Aug 26th, 2004, 02:06 PM
#3
Thread Starter
Fanatic Member
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!
-
Aug 26th, 2004, 04:01 PM
#4
Hyperactive Member
-
Aug 26th, 2004, 04:15 PM
#5
Hyperactive Member
Ok and this fixes that 
VB Code:
Private Sub MakeBrowser(ByRef ppDisp As Object)
Dim frmWB As frmWeb
Set frmWB = New frmWeb
frmWB.WB.RegisterAsBrowser = True
Set ppDisp = frmWB.WB.Object
frmWB.Visible = True
End Sub
Private Sub WB_NewWindow2(ppDisp As Object, Cancel As Boolean)
MakeBrowser ppDisp
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! 
-
Aug 26th, 2004, 04:45 PM
#6
Thread Starter
Fanatic Member
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!
-
Aug 26th, 2004, 04:52 PM
#7
Hyperactive Member
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! 
-
Aug 26th, 2004, 06:13 PM
#8
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|