In App there is an event called handleURL where I can extract url parameters and make decisions on what to present back to the user based on the query.
I have built a custom web page to respond to that url.
I have a myWebPage class that is to be the response to be displayed to the requestor.
When you create a webapp in xojo you get an app instance and a session instance…
I’m wondering why there is only one session instance rather than an instance for each session…
I would have expected to see an array of Sessions that belongs to the App.
Yet there does seem to be a notion of session at index therefore has the session already been created for me and in handle url I can pass the parameters to a method of the session or myWebPage?
Should i have derived mySession from Session and should I have set the session reference in app?
When you open a Xojo web app it is always going to open the single default page unless you hijack the request process and change it (Session.Open for example).
Because Xojo web is a single page application there really is only one actual page so querystring is discouraged. There are use cases if you are being redirected from somewhere else and you need those parameters. In that case you can use the RawHeaders property to parse out the querystring from the first header line.
Alternatively if you control the source application doing the linking you can change the first question mark to a pound symbol and access the Session.HashTag property.
How and when do I extract these parameters?[/quote]
Hey Brian,
When you load a url like that in a browser, the HandleURL Event Handler in App will fire passing Request As WebRequest. You can get the parts of the request from:
To send a response, check out the docs / example for WebApplication.HandleURL:
[quote]// Don’t override an empty request, or a session won’t start.
If Request.Path <> “” Then
// First, create the HTML answer
Request.Print “”
Request.Print "Oops! You took a wrong turn. "
Request.Print “Please put it in reverse and try again.”
Request.Print “”
// Set the status code. The default value is 404,
// but if you leave it that way, some browsers
// will show their own. A value of 200 will make
// the browser show your text instead.
Request.Status = 200
// You MUST return True if you want to override the output.
Return True
End If[/quote]
@Phillip Zedalis Nope I don’t see anything in RawHeaders.
@Hal Gumbert So I can loop through the sessions and call a method of that session to pass the session the parameters?
Assuming there is a session id as part of the url can I not call a ‘safe’ method of that session class instance?
For i As Integer = 0 To App.SessionCount - 1
if identifier = App.SessionAtIndex(i).identifier then
App.SessionAtIndex(i).AcceptParameters(q)
context.Session.CurrentPage = New handlerPage // Can I change this based on other parameters?
return ???
end if
Next
Return ????
App.HandleURL doesn’t have any connection to WebPages or Sessions. But like you said, if you pass the session ID in the URL, you could insert the code you just posted within the code I posted from WebApplication.HandleURL docs page.
subsequent request when button on gui pressed should be
dim url as string
url = "http://localhost:8086/special/?identifier=" + identifier + "?name=bob?id=123"
ShowURL(url)
I have no indication that no parameters were passed on the first invocation.
If I fudge the sessionID and put it in manually the second call works fine, but I’m confused as to how to get the session id in the web page instance.
Brian, as I mentioned on your other thread, please go look at Session.open. You can access the url parameters from there and set up their initial state appropriately.
@Brian O’Brien I took a look at your sample project and have fixed it up.
There were a few problems:
As @Andrew Lambert mentioned, the data URL should use “&” to separate the params, “?” designates the start of the params.
You weren’t setting the webpage’s identifier property so the URL had a blank one, it’s now set in the page’s Open event.
Using ShowURL without it opening a new window meant you were replacing the current page with the data URL and therefore closing your session. It’s now set to open in a new window, you might need to change your pop-up blocker settings to allow it.
You had the wrong control name for the listbox, that’s fixed now.
It works, but I’m very confused as to what you’re trying to accomplish.
If all you want to do is populate the list with some data, you don’t need to be using HandleSpecialURL at all, just call a function on your page that populates the listbox with data. Heck, you could do it straight from the button action if you’re in cowboy mode.
I’m guessing this is just a test app for something else and I’m just missing the point of calling back to the App with a fresh URL.
You’d be much better off using something like Xojo.Net.HTTPSocket instead of ShowURL for sending the test data, that way a new page isn’t needed.
I found the session id in the session event… I just didn’t have a WebPage instance to send the session id to…
but in the web page instance i found a session that had the id.