In Web 2.0 how do I get the URL that is being used to run my app?
I’ve tried Session.URL but it doesn’t seem to work.
What am I doing wrong?
In Web 2.0 how do I get the URL that is being used to run my app?
I’ve tried Session.URL but it doesn’t seem to work.
What am I doing wrong?
If you use Lifeboat to deploy your Web App you can rely on the Host
header to tell you. This psuedo code will illustrate better:
// Set the proper prefix
var sProto as String = if(Session.Secure, "https://", "http://")
// Session.URL can't be set so create your own property to store it.
Session.BaseURL = sProto + Session.Header("Host")
The Session.URL
property only seems to be showing me the Session ID in debug. Using the Host
header works in debug and production, so I like that route.
I will be deploying using Lifeboat but wanted to test. I’ll add that to my list when I deploy and test it.
The Session.URL doesn’t even show me the URL in debug.
Hmm, I’m not sure.
Can you share a sample project here on the forum? Perhaps there’s some nuance that we’re not communicating. Here’s a simple project that’s working for me:
demo.xojo_xml_project (3.0 KB)
By the way, using the Host
header the way I do is designed to work in debug as well. I use this method myself.
I was using it at a Shown event. Let me check out what you have provided and see what I’m doing wrong. Thanks
That is the Session ID, it would match Session.Identifier.
It looks like that’s all we get unless we pass a --BaseURL
parameter by command line to tell the web app where it’s running. In my opinion that’s probably not what you are looking for, since you asked to get the URL. I’m understanding this to mean you’d like to detect what the URL is so you don’t have to hard-code it.
If that’s the case, the method I posted above will help you determine the URL at runtime.
I have updated and expanded the demo project a little bit to show you some options.
Download: demo.xojo_xml_project - 11kb
Changes:
App.URL
property using code from Post #2 above--BaseURL
parameterThanks so much.
Alan