Getting a Session from HandleURL

Hi All,

I am struggling a bit with Sessions and HandleURL.

When my users browse to a sample URL like:

http://host/path/to/endpoint?key=value&key2=value2

I have to use the HandleURL in the main thread (app).
But I have no session reference (they can just paste this thread into the browser) and I need to pass some values back, but there doesn’t appear to be anywhere to do so. When I try to reference a web page it is throwing a Nil Object Exception.

It is striking me as a bit of a catch-22, but I suspect that is out of my own ignorance.
Where am I going awry?

Thanks.

That is by design You have to create your own session handling if needed when using Handleurl

Hi @Steve Koger , thanks for the reply.

Is there a sample project that demonstrates that or some other bit of code somewhere that could point me in the right direction?
I have searched around, but nothing is readily showing itself.

Thanks.

When a user hits a virtual directory and triggers HandleURL, no session is created. So you cannot display any webPage.

That is why the example in the LR shows how to display an HTML page. That is how you pass values back eventually.

Hi @Michel Bujardet , thanks for the reply.

Forgive my ignorance here…
OK, so at what point is the Session created?
Would it be after the HTML is returned?
If so, how do I direct or redirect the user to an actual Webpage object?

For the sake of clarity: I am emailing them a link to reset their password and they need to click on that link in order to get the page to reset their password. Not sure if that helps or not.

Thanks very much for your time.

HanhleURL is intended to be used in situations which would otherwise result in a 404 error, so there should be no need for a session to respond to this error.

Check out this page in the docs for handling url parameters in your web app.
WebSession.URLParameter

http://yoursite.com/?action=reset&key=value&key2=value2

In session.open, based on the url parameters, you could show a password reset page and lookup the correct user information.

Hi @James Dooley and @Scott Siegrist ~ thanks for your replies.

Scott ~ that my be just the ticket. I will play with that and go from there.

THANKS!

You can direct a user to your app from HandleURL with a redirect:

[code]

<BODY [/code] http://documentation.xojo.com/api/web/webapplication.html#webapplication-handleurl If you request.print the code above from HandleURL, you will send the user to new-website. In your scheme, simply point to your app executable, or port, maybe with some tags that will help the app know where to take the user.

At that point, the app will create the session and present the user with a WebPage.

[quote=436983:@Michel Bujardet]You can direct a user to your app from HandleURL with a redirect:

[code]

<BODY [/code] http://documentation.xojo.com/api/web/webapplication.html#webapplication-handleurl If you request.print the code above from HandleURL, you will send the user to new-website. In your scheme, simply point to your app executable, or port, maybe with some tags that will help the app know where to take the user.

At that point, the app will create the session and present the user with a WebPage.[/quote]

Yep, that is the kind of thing you’d expect to find in this event. Perhaps also logging the incorrect request as well for a security review later.

Is it possible to respond with a 301 or 302 and new location from HandleURL?

Yes. That and a Location header would work just fine.