Websession.URL gets the Identifier? Bug?

If I use the “Session.URL” I get the Identifier with a slash in front:

Var currentSession As Session = Session

#If DebugBuild Then
  code  = currentSession.URL
#Else
  code  = Session.URL
#Endif

URL.ToText does not change anything.

I need this because I want to use the same App with different domains for sending mails with the domain name used by the user. Did I miss anything? Is the identifier to be converted somehow? Any idea? Thanks a lot!

In the session the Session.URL always returns the url to the session. But in stand-alone it will never return the host and/or it’s protocol so you won’t see “http://myapp.tld

Try using

App.URL + Session.URL

I know. It does give the same result running as a built Linux server.

Sorry, did not work.

@Michael_Dettmer
It would be really helpful to see an example of what you need then, so we’re not just stabbing in the dark.

1 Like

Should App.URL documentation be on this page?
https://documentation.xojo.com/api/web/webapplication.html

Did you try on a build application on the server where you visit using https://example.com or just locally?

Both. Both give back the identifier only.

So App.URL is always empty (both locally and when running on the server and accessed with a name and not by IP)?

Sorry, I do not get it. The code is above, it is in the “Open” event of a page. The variable “code” should show something like “http://blabla.com:4711” … or if the user comes with another domain “http://xyzxyz.com:4711”. What do you want me to show, it’s a one-liner?

Or did I miss something? May be I misunderstood something? Thank you!

App.URL is empty on all trys and Session.URL always contains the ID with a slash in front. No matter if debugging or live on the server.

I don’t think that Session.URL gives you the host and connection, so you will not see http://blabla.com:4711

I guess App.URL can give that information, but I can’t find the Documentation for that. Maybe not.

I don’t know if RawHeaders can give you the host and maybe you can pull the information from that?

Edit: tested locally, 127.0.0.1:8080 is shown in RawHeaders, changed to localhost:8080 and that showed too as Host:

Nice. This works. Thanks again for this nice workaround!

Still the question if this is a bug. In the docs it should give back a URL, what is not the case. No example found for that. Should I open an issue?

If you want to open an issue. It may only be a documentation problem.

URL for some people is the complete address including the protocol and the host, for other people, the URL could be only the relative part against the server/protocol used, so the URL can be just /index.html (for example) or what we are getting with Websession.URL

I’m intrigued about App.URL posted by Greg, should that show the host part of the URL? should that show also the protocol (http or https)? I can’t find information about that. It seems that App.URL is just an empty string.

The URL property seems to be legacy. From the old Web 1 docs:

WebApplication.URL:
The SCRIPT_NAME for the web app. For example, for a web app running on http://www.example.com/cgi-bin/example.cgi, this returns “/cgi-bin/example.cgi”. For standalone web apps this always returns the empty string.

Web 2 always run as standalone server, so this property will be always empty.

I would expect also to get the full URL, including the schema. You can achieve it with something like this:

Var baseUrl As String = If(Session.Secure, "https", "http") + "://" + Session.Header("host")

Thanks, this is very helpful. Anyhow I would expect, that I get the “callers” URL with the property Websession.URL like described here:

URL As String
Returns the URL to the session.
This property is read-only.

I think this is not “legacy”, is it? :roll_eyes:

It’s better to not have the base URL and the session path glued together by default, it’s easy to concat them anyway:

Var baseUrl As String = If(Session.Secure, "https", "http") + "://" + Session.Header("host")
Var sessionUrl As String = baseUrl + Session.URL

As far as I know, Session.URL never included the base URL.

Finally what you say: The URL never included the URL? :person_shrugging:
May be another idea to rename something in Xojo … :crazy_face:

1 Like

Session.URL never included the base URL, but the path portion.

@Ricardo_Cruz

Maybe better move this to Session.Path and fix Session.URL to have the actual url:

If(Session.Secure, "https", "http") + "://" + Session.Header("host")

The naming should say what it actually gives, since it does not give a URL but a path, this should be changed.

For Session this is an easy fix since this knows the host and the protocol. App.URL seems to be useless unless the first call to App.HandleURL Or a session where xojo may set this.

1 Like