Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

window.open() causes session context to be lost

Posted on 2004-04-08
15
Medium Priority
?
4,208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Implementing Azure Infrastructure Exam 70-533

This course is designed to familiarize and instruct students in the content that is covered by Microsoft Exam 70-533, Implementing Microsoft Azure Solutions. It focuses on all the November 2016 objective domain topics.

 
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 1500 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
 
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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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