24-Jun-04 (Created: 24-Jun-04) | More in 'CS-dotnet'

Internet Explorer Web Control looses session cookies in response to a new window

Problem

When an internet explorer control is embedded in a power builder window, the internet explorer seem to loose session cookies for popups. Obviously this is not desirable for a reason. This drawback prevents from embedding fully functional web applications inside of a client server systems such as those built powerbuilder, delphi, or home grown.

Good news

We know why it happens. An ole control like the IWebBrowser2 that is embedded in a powerbuilder windows, runs under the aegis of the parent powerbuilder process. When a new window or pop up is invoked, a new ie process is started and hence has its own new cookie set.

Good news again is that there is work around. IE says you can stop it based on the following article

HOWTO: Use the WebBrowser Control NewWindow2 Event

the ole control fires a "new window" event giving the powerbuilder a chance to give it a powerbuilder window to live in. This is reiterated in the following article:

An MDI-Style Web Browser and Load Spy Monitor By Zuoliu Ding

I also have found some more detailed explanation from google groups in the following post

Read IE5 control problem with NewWindow2

I have got a bit bolder and searched the web for "newwindow2" and "powerbuilder" which yielded the following post on a power builder forum:

Read PB does OCXs: Web Browser example

Importantly the above very detailed code enladen post shows how to capture the ocx events including our star event the newwindow2 event.

Bad news

The work around is not a simple configuration parameter. One has to be able to do the following:

1. Know how to intercept the ole events in the powerbuilder app either directly or writing another wrapper OLE object

2. You have to know how to create an appropriate power builder window that can be passed to the new window ole pointer

Search words in google

While searching for the related material in google it might interest the reader to note the following key words in their order of narrowness/importance descending.

NewWindow2 powerbuilder
NewWindow2
184876
311282
IWebBrowser2
ie new window session cookies

Sometimes when you do searches all day for a given topic of research you want to know the important ones for future reference. Unfortunately ie doesn't keep track of these searches on the webform that searched. To see all your searches, go to "history". In ie you can do this by going to "view/explorer bar/history". Under the google you will see the list of searches you have done for the day. From those write down the most yielding search keys.

On searching in google

Starting with the idea that new windows are not keeping cookies I would not have imagined or zeroed in on the final search that produced desirable results. The final search is "newwindow2 powerbuilder". It is quite interesting how I have arrived at those key words. While searching in google the first thing to note is to search both the web and the news groups. Web continues to get more relevant but still for some questions news groups offer better results.

The second thing to note is to increasingly narrow the search. Once you know the actual apis that are involved in the operation then you can focus on the search for those apis. The idea is to see how one can embed a webbrowser inside of a winow. This is done through an ocx control. But do we know which one? This lead me to IWebBrowser2. See if anyone has reported problems with it regarding cookies.

That lead me to a kb article from msdn numbered 184876. I have looked at it and saw them talking about NewWindow2 event. Now this got more specific. Somehow in the process I have forgotten to book mark kb reference but I wrote down the number. So back to google with the number. This yielded an interesting insight. Now I not only have retrieved the article but also saw various other articles that talked about the same subject. So these msdn numbers are wonderful search tools in cross referencing.

Now armed with NewWindow2 event I pretty much got what I wanted. As I said at this point I have got a bit brave and said why not qualify with power builder. There it is the narrowest and fruitful search of this exercise.

Nurturing experts

This time I am lucky, and increasingly getting luckier with the help of google. But before google the approach was a bit involved. This approach will involve identifying a set of experts in the field. Find news groups or mailing lists where these experts usually hang around. A good mailing list is not too large or not too small. Some examples are the mailing lists from the Develop Mentor training company. Subscribe and stay there for a few months and get to know the experts. This becomes your source for debugging these problems and seeking guidance, feedback etc.

Searching these mailing lists for content is also another fruitful exercise. You want to narrow down on the threads that are widely discussed and also on the posters that regularly post.