Web Sessions

I have some session variables I want to access form another window
How do I set the webcontext from the original session.

Thanks

Tim

I think there are several ways to do this, as long as you keep track of both the original session and the user. I suggest saving the session identifier in a session cookie that could be picked up when the second window/session is opened. Assume for simplicity that it is another instance of the same web page, WebPage1, and that ImplicitInstance is True.

WebPage1 has the following properties:

myIPAddress As String myOldSession As String myFirst As Boolean=True myProperty1, myProperty2 etc. corresponding to the variables in Session

In the Open event of Session you would have the following code:

If self.Cookies.Value("sessionID")<>"" Then WebPage1.myOldSession=self.Cookies.Value("sessionID") //gets previous session identifier from cookie WebPage1.myIPAddress=self.RemoteAddress WebPage1.myFirst=False Else self.Cookies.Set("sessionID", self.Identifier) //sets a cookie containing session identifier if first session End If

Session has properties oldProperty1, oldProperty2, etc. where your variables are stored. WebPage1 has the following code in a WebContainer or some other control:

[code]If myFirst=False Then
Dim mySession As Session

If Session(App.SessionWithIdentifier(myOldSession, myIPAddress))<>Nil Then
  mySession=Session(App.SessionWithIdentifier(myOldSession, myIPAddress))
  myProperty1=mySession.oldProperty1
  myProperty2=mySession.oldProperty2  //and so on
  
Else
  MsgBox  "An error occurred or the other window was closed too soon!"
End If

End If[/code]

Wait a sec. If all you are trying to do is to share properties between WebPages, just add them to the Session object. They’ll be available to every page in the same session by just calling Session.MyProperty. Remember, a unique Session instance is created for every user of your app.

That would be a lot simpler!

I gathered from Tim’s question that he wanted to share properties between two sessions running in different windows of the same browser.