Monday, November 05, 2007

Modal Dialog session expiry issue in IE 6

In our application we were facing a very queer problem. One of our page flows was opening a modal dialog from another modal dialog. While doing this we were facing an intermittant problem of 'session-expiry'. I put a sniffer on the client machine and saw that a new sessionID was generated. This meant that the JSESSIONID cookie was not being propogated to the child windows.
I also realised that this problem was only with 'Modal Dialogs' and hence IE specific.

I tried in vain to understand where we were doing things wrong. Lady luck was shining on me, when I found this link that explains the problem.
Snippet from the microsoft site:

When Internet Explorer opens a window from a modal or modeless HTML dialog box by using the showModalDialog method or by using the showModelessDialog method, Internet Explorer uses Microsoft Component Object Model (COM) to create a new instance of the window. Typically, the window is opened by using the first instance of an existing Internet Explorer process. This process is different from the process that Internet Explorer uses to open a new window by using the window.open method.
When Internet Explorer opens the window in a new process, all the memory cookies are no longer available, including the session ID.

The workaround was to pass the window object of the parent of the dialog box into the dialog box, and then use that object to open the new window.

For e.g. In the parent window:
var args = new Object;
args.window = window;
showModalDialog("modal.asp", args)

And in the child window:
dialogArguments.window.open('page1.asp')

No comments:

Post a Comment