• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4322
  • Last Modified:

window.open() causes session context to be lost

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
KarunSK
Asked:
KarunSK
  • 6
  • 3
  • 2
  • +4
1 Solution
 
KarunSKAuthor Commented:
Oh, I forgot to mention that the sessionState mode is SQLServer.
0
 
HigorCommented:
Im not sure i understand, you open another page with window.open and the session are not keeped? Is that correct?

0
 
KarunSKAuthor Commented:
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
[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 
majodioCommented:
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
 
Arthur_WoodCommented:
How are you using window.open from you ASPX code-behind.

Please show the code you are using.

AW
0
 
KarunSKAuthor Commented:
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
 
nishikanthCommented:
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
 
KarunSKAuthor Commented:
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
 
Vaishali_chaudhryCommented:
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
 
KarunSKAuthor Commented:
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
 
majodioCommented:
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
 
majodioCommented:
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
 
Vaishali_chaudhryCommented:
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
 
ihenryCommented:
>> 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
 
KarunSKAuthor Commented:
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now