Control could not be created because there is currently no Session. Create a Web Session Context object

How i create a new Web session contex in 2023r1.1?


When you run code in a timer, you may need to tell Xojo which session this belongs to.

i have already look at this documentation but i can’t find a solution.Can you help me with another way?

Could you tell us where it happens?

you may need to use something like this in the event:

Var context As New WebSessionContext(mySession)

where mySession is a session object or identifier, which you stored somewhere beforehand.

Usually the place I see things like this are:

  • App.HandleURL event
  • Timer.Action event (not WebTimer)
  • Socket events (like URLConnection, TCPSocket, UDPSocket)
  • SerialPort events

In all of those cases, the events run on the main thread, completely disconnected from any of the currently running sessions. WebTimer is a good example of a class that was created to deal with this.

Anyway, except for the App class, you can subclass any of the others like this:

  1. Subclass TCPSocket
  2. Add a private property mSession as String
  3. In the Constructor, mSession = Session.Identifier
  4. In the event where you need session access before any other code: dim context as new WebSessionContext(mSession)

You should still check to see if context is Nil in case the session ended while your code was running.

// Parse the query string from the URL
Dim query As String = Request.QueryString

// Process the query string parameters
Dim params() As String = query.Split(“&”)
For Each param As String In params
Dim keyValue() As String = param.Split(“=”)
If keyValue.Ubound = 1 Then
Dim key As String = DecodeURLComponent(keyValue(0))
Dim value As String = DecodeURLComponent(keyValue(1))

// Use the key-value pair as needed
// For example, print them to the debug pane
System.DebugLog(key + " = " + value)
if key = "shopcode" then
  Var w as new wpDashboard
End If

End If
When i try to open the new url.i get the error that i have to create a new web session contex

Right, and you’re doing this in App.HandleURL (which I can tell because your first line calls Request.QueryString). The problem is that HandleURL doesn’t consider sessions.

So if this is a link that comes from somewhere else that you want to send someone into a session, what you need is a redirect. You could do something like this:

Var url as string

url = if(, "https://", "http://") + request.header("host") + "?shopcode=" + value

Response.Header("Location") = url
Response.Status = 302
Return True

Then in Session.Opening, you’ll need to look for the shopcode parameter and redirect the user from there.

Var shopcode As String = session.URLParameter("shopcode")

can you give more specific details?
cause i am new to xojo

I’m not sure how to be more specific.

It would be helpful to know what the incoming URLs look like though, because you’re going to need to have a way to allow browsers to request a new session.