Solved

window.open() causes session context to be lost

Posted on 2004-04-08
15
4,006 Views
Last Modified: 2008-03-17
Hi,

I am trying to open an ASPX page using window.open() from codebehind. The new page accesses some large session variables (CrystalReport stuff like EnterpriseSession and InfoStore objects) that were populated in another page. If I don't call this page in a new window, and do a Server.Transfer() or Response.Redirect(), I am able to retain these variables and use them. But opening the page in a new window causes these variables to be lost!

Note that this happens only to large objects and not the small ones one would usually use (like strings).

Is there any workaround to this? I cannot add the variables to ViewState since the objects don't seem to be serializable.

Thanks,
Karun.
0
Comment
Question by:KarunSK
  • 6
  • 3
  • 2
  • +4
15 Comments
 
LVL 6

Author Comment

by:KarunSK
ID: 10788694
Oh, I forgot to mention that the sessionState mode is SQLServer.
0
 
LVL 5

Expert Comment

by:Higor
ID: 10799432
Im not sure i understand, you open another page with window.open and the session are not keeped? Is that correct?

0
 
LVL 6

Author Comment

by:KarunSK
ID: 10806449
Yes, you have understood correctly. When I open a new window by attaching a window.open() from codebehind to the aspx page, any large session variables are lost. But smaller ones (like UserName) remain.

Karun.
0
 
LVL 2

Expert Comment

by:majodio
ID: 10870980
Hmmm, interesting problem.  I'm not sure why smaller ones would remain while larger ones are deleted.  Are you sure that you're not repopulating the username session variable if it doesn't exist?

I would focus your efforts on figuring out how to make the object serializable so it can be inserted into the viewstate or a database.

It looks like you've posted your problem in the news groups as well...  Did you happen to see this:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=108096jcuoi772a%40corp.supernews.com&rnum=1&prev=/groups%3Fq%3DLarge%2BSession%2BVariables%2BLost%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10871050
How are you using window.open from you ASPX code-behind.

Please show the code you are using.

AW
0
 
LVL 6

Author Comment

by:KarunSK
ID: 10873689
Thanks for the replies.

majodio:
No, I am not repopulating the smaller session variables if they don't exist. The problem clearly is that larger objects are getting lost.

I did read and reply to the posts; they didn't solve my problem. Strange the complete thread is not there -  I posted my question through MSDN newsgroups, and looks like only a part of the thread is present in google groups; this is not the first time I see this behavior either.

Arthur:

This is what I do:

        Dim l_SessionManager As New SessionMgr
        Dim l_ESession As EnterpriseSession
        Dim l_EnterpriseService As EnterpriseService
        Dim l_InfoStore As InfoStore

            l_ESession = l_SessionManager.Logon("UserName", "Password", "ServerName", "secEnterprise")
            l_EnterpriseService = l_ESession.GetService("InfoStore")
            l_InfoStore = New InfoStore(l_EnterpriseService)

            Session("ESession") = l_ESession
            Session("IStore") = l_InfoStore

Later, I conditionally open a new window like this in one of the events:

        If (user navigating from a particular screen) Then
            Dim strNewWindowScript As String
            strNewWindowScript = "<script>window.open('DifferentPage.aspx');</script>"
            Page.RegisterStartupScript("NewWindow", strNewWindowScript)
        Else
            Try
                Server.Transfer("DifferentPage.aspx", True)
            Catch ex As Threading.ThreadAbortException
                'Do nothing
            End Try
        End If

When the page opens in a new window, I can see (through page-output-enabled-trace) that the session variables are no longer present. Whereas, if it opens in the same page, I am able to see them being retained.

Karun.
0
 
LVL 8

Accepted Solution

by:
nishikanth earned 500 total points
ID: 10875022
Which IE version you are using... this is a problem with the IE...

chech this MS KB

http://support.microsoft.com/default.aspx?kbid=196383
http://support.microsoft.com/?kbid=240928

http://aspfaq.com/show.asp?id=2157
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Author Comment

by:KarunSK
ID: 10884460
Nishikanth,

Thanks for the excellent links - especially the aspfaq. (The MS support articles are related to IE 4 or 5, and I have 6.0.)

I did some research myself after my original post and came up with this:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&frame=right&th=fd886074ef4196e0&seekm=OqwrQdpgDHA.1764%40TK2MSFTNGP09.phx.gbl#link1

and a couple of other links that I've subsequently lost :-(

I had a suspicion that IE would be the culprit. I wanted other opinions though, which is why I posted here. The articles I have read so far discourage me from using a window.open() but there is no other way I can show my aspx page in a new window. AND I want my session variables. Looks like I cannot have them both.

Let me wait a day or so for other posts - to see if anybody has any workarounds through code, then I will close this question.

Thanks again,
Karun.
0
 
LVL 2

Expert Comment

by:Vaishali_chaudhry
ID: 10885846
The potential problem that i feel is you loose big seession variables and the smaller ones remain...try using the ASP.NET new Cache object to store the session objects ...that might help.
0
 
LVL 6

Author Comment

by:KarunSK
ID: 10893007
Vaishali,

Thanks for the post. I cannot use a Cache object as it is common to the whole application, and I am using session-specific objects.

Karun.
0
 
LVL 2

Expert Comment

by:majodio
ID: 10899013
Have you tried using the application object instead of the session object?  You will need to clean up after yourself, but that should work.
0
 
LVL 2

Expert Comment

by:majodio
ID: 10899055
You could do something like this:

        Dim l_SessionManager As New SessionMgr
        Dim l_ESession As EnterpriseSession
        Dim l_EnterpriseService As EnterpriseService
        Dim l_InfoStore As InfoStore

            l_ESession = l_SessionManager.Logon("UserName", "Password", "ServerName", "secEnterprise")
            l_EnterpriseService = l_ESession.GetService("InfoStore")
            l_InfoStore = New InfoStore(l_EnterpriseService)

            Application(Session.SessionId & "ESession") = l_ESession
            Application(Session.SessionId & "IStore") = l_InfoStore

You'll also need to be sure to manage the thread somehow, but if you could pass in the session id into the page that you are opening you could query the correct Application variable.  You would also want to setup a cleanup mechanism in your global.asax to remove application variables when they become obsolete.

Let me know if you understand this or if you need more details.
0
 
LVL 2

Expert Comment

by:Vaishali_chaudhry
ID: 10915474
hi Kauun,

I had a similiar porblem where i had to make a file on the webserver which should get deleted automatically after the session expires... i used the ASP.NET Cache object (not to store anything ) just to make use of the callback function. This callback got called as soon as the session expired and would delete the file from the filesystem.You could do something similiar by storing the session variables in the cache and removing them from the cache after the session expires using the callback....give it a thought ...

And it is better the  using Application variables with all the asp.net cache manager features.
0
 
LVL 20

Expert Comment

by:ihenry
ID: 10936532
>> I can see (through page-output-enabled-trace) that
>> the session variables are no longer present
1. Did you see the new window has the same session id?

>> Oh, I forgot to mention that the sessionState mode is SQLServer.
2. Do you use tempdb or a dedicated table to store the session?
3. Since the session is stored in a table for each session id, have you checked before and after open a new window whether the record is exists?

4. Is that happened if for hyperlink to open a new window?
0
 
LVL 6

Author Comment

by:KarunSK
ID: 10941738
Thanks again guys for the replies. Please bear with me for the delay - will check the approaches suggested and get back to you ASAP.

ihenry:
1. Yes, the session ids are the same in the new window too.
2. I am using the default database and tables (AspState) to store the session.
3. I haven't done this; will have to check it out.
4. You probably mean a target="_blank" invocation - I am not using it to open new windows, just the script - but will try this out anyway and see if it makes a difference.

Thanks again,
Karun.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now