WebPage.Show from HandleURL

I did some searching on this, and I’m still confused. :frowning:

I understand that there is no session when I enter the app via HandleURL, so I’m trying to start a session and go to a Xojo WebPage when I load url like ‘http://127.0.0.1:8080/admin’. I plan to handle all other URLs via building html and Request.Print.

dim thePath as string = Request.Path.Lowercase select case thePath case "admin" dim theSession as new Session() theSession.PageWithName( "WebPage1", true ).Show end select

But that’s not working…

AFAIK you simply cannot start a session from thin air.

To take the user to a new page, use this :

Function HandleURL(Request As WebRequest) As Boolean Request.Print("<script>location='http://fontmenu.com'</script>") Return true End Function

Thank you Michel. That would work, but I’d like to to to a Xojo WebPage in the same web app as the HandleURL.

I could reverse the process and start on a Xojo Page and then redirect to HandleSpecialURL, but that would mean that the path would be require /special/ or /api/…

Tim Dietrich suggested that I create two web apps. One that uses HandleURL and other one for Admin stuff.

Is it correct to say that if you use HandleURL, you can’t use Xojo WebPages? The only way I can seem to get to a Xojo WebPage is to delete all my code from HandleURL.

Don’t bother with convoluted methods. You cannot display webPages from HandleURL, but you can from your app. It is just a matter of telling it which.

Here is an example :
Function HandleURL(Request As WebRequest) As Boolean
if Request.Path = “Page2” then
Request.Print(“”)
Return true
end if
End Function

In Session.Open, verify the hashtag and display the requested page :
Sub Open()
if Hashtag = “Page2” then
WebPage2.Show
end if
End Sub

Session.Open doesn’t seem to be triggering. When handleURL runs, it is going to the URL with the hashtag, but HandleURL seems to be intercepting it.

Thank you so much for helping!

You don’t understand. HandleURL lets you use a virtual path /Page2. If you simply run it does nothing.

You need to point to http://127.0.0.1:8080/Page2 for the code above to work.

Run the app, then open a new browser and go to http://127.0.0.1:8080/Page2

Thanks for your patience. I think I found the problem. I was handling request.path = “” which was preventing it from getting to the Xojo page.

I think I can have it do what I want by having the session redirect back to a non blank request.path like “home”.

That did the trick Michel! The problem was that I was handling request.path = “”. I need to let the root get to the session and then redirect back to “/home” so I can process the home page.

HandleURL

[code] dim thePath as string = Request.Path.Lowercase

select case thePath
case “admin”
Request.Print(“”)
Return true
end select

if thePath <> “” then

Request.Print thePath

// Send to the Browser
Request.Status = 200
Return True

end if [/code]

Session.Open

[code]if Hashtag = “admin” then
AdminPage.Show
end if

if Hashtag = “” then
ShowURL “/home”
end if[/code]

Hal, I also had that problem.

Michel, this also would have helped me in the thread https://forum.xojo.com/35760-handleurl-executeevent-and-webcontrolwrapper-is-possible-work-t/0

It could be a way to use handleurl first, then you can use a webcontrolwrapper within a webpage, and thus be able to run javascript code (calling Xojo.TriggerServerEvent javascript function), then I can bring back to a ExecuteEvent event.

Very good idea!! :slight_smile:

Excuse me, I’m trying to redirect that way, and Open or HashTagChanged event Session is not triggered :frowning:

I have this code in App.HandleURL:

if Request.Path = “Result” then
Request.Print ( " location = ‘/#Result’ </ script>")
Return true
end if

And in Session. Open / HasgTagChanged:

if Hashtag = “Result” then
WebResult.Show
end if

In HTML file, open frame:

...

I have to open somehow special session to jump your events?

I’ve even tried directly insert the url in the browser: http://localhost:8080/Result

It jumps to the following address: http://localhost:8080/Result#Result
but it does not pass through the events of the session.

Directly on url address bar skip the event too:
http://localhost:8080/#Result

It works here.

Attention : HandleURL is triggered only with

http://127.0.01:8080/Result

It is not the same as

http://127.0.01:8080/#Result

Could it be the problem ?

[quote=292756:@Michel Bujardet]It works here.

Attention : HandleURL is triggered only with

http://127.0.01:8080/Result

It is not the same as

http://127.0.01:8080/#Result

Could it be the problem ?[/quote]

HandleUrl functions correctly. The problem is Session Open event, does not fire.

Use :

if Request.Path = "Result" then Request.Print ( "<script> location = 'http://127.0.0.1:8080/#Result' </ script>") Return true end if

[quote=292761:@Michel Bujardet]Use :

if Request.Path = "Result" then Request.Print ( "<script> location = 'http://127.0.0.1:8080/#Result' </ script>") Return true end if[/quote]

Continue without execute event “Open” of Session.

I just avoid going into an infinite loop with the Iframe, but is not the problem I was seeing now.

Grmbl… This works here :
https://dl.dropboxusercontent.com/u/17407375/handleurl.zip

Run the project, and open a new page to http://127.0.0.1:8080/Result
It will redirect you to http://127.0.0.1:8080/#Result

Note that I packed DebugView into the zip, as it is necessary to receive System.debuglog under Windows for web apps. If you are under another platform, no need.

Thank you very much !!! I did not know that I could debug running that way :slight_smile:

I create a new project from scratch working with the Open event of the Session, in the same way that the project that you give me.

However, I could not execute alright in my application.

I have observed that the HandleURL event when execute the statement:

Request.Print ( "<script> location = '/ # Result' </ script>") 

first passed again by the HandleURL with path = “”, and then goes to the Open event of the session.

In my case, when the path = “”, performing other actions because the root directory is used it as index.html …

I keep trying…

HandleURL fires for all requests, including the regular traffic.

So path “” results simply from running in the IDE, when the app shows the main WebPage.

That is why you want to use a select case or if then to make sure the redirect occurs only when you have a certain path.

Ok Michel. Eureka !! Now the problem is this: The HandleURL with path = “” is used to reach the Open event of the session. If I want the execution of the root directory upload an index.html file, the only thing I can think of is to create a global variable, that when it passes the url / Result is set to true, and when passing through the path = “” in HandleUrl, is set to false when true comes, and that intercept way. Example:

On HandleURL:

select case Request.Path
case ""
    if comesfromHandleURL = false Then
       Request.Print(HTMLCodeIndexPage)        'Load index page
    else
       comesfromHandleURL = false
     end if
case "Result"
     Request.Print ( "<script> location = '/#Result' </script>")
     comesfromHandleURL = true
     Return true
end select

Manuel, I am afraid you do not quite understand.

Path “” means a normal access to the app (session open). It cannot occur otherwise. You do not have to do all you do.

Simply keep “Result” and forget about “”. You will be fine.

select case Request.Path case "Result" Request.Print ( "<script> location = '/#Result' </script>") comesfromHandleURL = true Return true case"somethingelse" // end select

[quote=292807:@Michel Bujardet]Manuel, I am afraid you do not quite understand.

Path “” means a normal access to the app (session open). It cannot occur otherwise. You do not have to do all you do.
[/quote]

Michel, when the “” path i load index.html page from html file.

For example:
Well call: http://localhost:8080
loads html file from disk.

If I do not control where it comes from, is not execute the Open event of Session, and only displays the html code of the index page, and I know no other way to call the main html file from the web server root virtual directory.

You still do not understand what I try to do?