Recently this project extended and was used to hold a complex ASP.NET webapplication, which gave some additional problems with the ASP.NET Session object. The problem is that this webapplication popups several windows (Internet Explorer windows) which looses the session of the webapplication.
As a result the user must login on every browser, which is a showstopper of course.
The cause of this is that the webserver sees our application as a different process compared to Internet Explorer. (ASP.NET sessions are process dependent) Different process, different session. The solution of this was rather simple, although a little hard to find.
How to retain the browser session within your application
The trick is to get the popup to run into the same process as our application, so basically to run it in our application.
TWebbrowser has a NewWindow2 event for this. In this event you can specify the application to be used throught the ppDisp (IDispatch) parameter. (our application, in this event)
Suppose you have a second form, Form2, containing another TWebbrowser, you could 'redirect' the new window like this:
procedure TForm1.WebBrowser1NewWindow2(ASender: TObject;
var ppDisp: IDispatch; var Cancel: WordBool);
ppDisp := Form2.WebBrowser1.Application;
Quite simple, isn't it?
To let our form act in the window-name resolution it is wise to set the RegisterAsBrowser property to true.
More information can be found on knAlertz:
How to maintain the ASP.NET session state
How to use the WebBrowser control NewWindow2 event in Visual Basic .NET