handleUrl what can and can't we do?

I get an Internal Server Error when I try to access a xojo webPage in the handleUrl method.
I was wondering if there is a way around this. i.e. is it actually possible to access xojo pages here or am I miss using handleUrl. i.e. it is not designed to allow this.

to give some context…
Ive created an app to serve up a product display in an iframe in a website through my webPage “productViewPage”

The startup page goes to my maintenance screen and is designed NOT to use in an iframe. i.e. its accessed the normal way.
ie
http://111.61.111.111/cgi-bin/product/product.cgi

I was hoping to use handleUrl and add a url snippet to the end on my site string in the iframe to redirect the iframe to the correct page
ie
http://111.61.111.111/cgi-bin/product/product.cgi/public

so I tried

If Request.Path <> "" then
   
    productViewPage.Show
  
    Request.Status = 200 /
    Return True
  End If

which creates the below error when it gets the show statement
Internal Server Error

The server encountered an unhandled NilObjectException while executing this request.

Can I actually achieve my objective in the method?
or am I barking up the wrong tree and this is not how handleUrl can be used.

Thanks for your thoughts…

[quote=159703:@James Nicholson-Plank]I get an Internal Server Error when I try to access a xojo webPage in the handleUrl method.
I was wondering if there is a way around this. i.e. is it actually possible to access xojo pages here or am I miss using handleUrl. i.e. it is not designed to allow this.

to give some context…
Ive created an app to serve up a product display in an iframe in a website through my webPage “productViewPage”

The startup page goes to my maintenance screen and is designed NOT to use in an iframe. i.e. its accessed the normal way.
ie
http://111.61.111.111/cgi-bin/product/product.cgi

I was hoping to use handleUrl and add a url snippet to the end on my site string in the iframe to redirect the iframe to the correct page
ie
http://111.61.111.111/cgi-bin/product/product.cgi/public

so I tried

If Request.Path <> "" then
   
    productViewPage.Show
  
    Request.Status = 200 /
    Return True
  End If

which creates the below error when it gets the show statement
Internal Server Error

The server encountered an unhandled NilObjectException while executing this request.

Can I actually achieve my objective in the method ?
or am I barking up the wrong tree and this is not how handleUrl can be used.

Thanks for your thoughts…[/quote]

WebPage.Show cannot be used within an app event, since a webpage has to be part of session to display.

Worse, ShowURL cannot be used either there. Although I do not really see why. Maybe we should put that as a feature request, unless there is some technical impossibility. Greg, are you around ? Is ShowURL in HandleURL a possibility ?

In the meantime, I needed precisely that feature, so I used a workaround (smile).

[code]Function HandleURL(Request As WebRequest) As Boolean
If request.Path = “” then return false

Request.Print “”
Request.Print “”
Request.Print “<META HTTP-EQUIV=”“REFRESH”" CONTENT="“0;URL=http://www.fontmenu.com/index.html”">"
Request.Print “”

Return True
End Function
[/code]

This in HandleURL will take the user to my site fontmenu.com.

If you want to take him to one of the pages in your app, you got to take the user to your app, and use the query string to display the proper page.

For instance
http://127.0.0.1:8080?page=productViewPage

In the Session Open event, put this, and the app will open directly on the page

Sub Open() if me.URLParameter("page") = "productViewPage" then productViewPage.show end if End Sub

I have used the debug URL, but of course this works fine as well with cgi or standalone on a host. If you want to test that on debug, run the project, and open the url in a new tab, otherwise the session will time out and the program will terminate.

For instance http://127.0.0.1:8080/Mysubfolder

Micheal
your a life saver,
thanks heaps.
your work around will work a treat

Can’t you simply add a parameter to the url and show the correct file in session.open based on that?

That is exactly what I put in the end of my post.

It is simple enough, but the OP question was specifically to go to a specific page from handleURL. It would have been extremely simple if ShowURL was available, but it is not, so the Refresh.

As for why one would want to use handleURL to lead to specific pages, one use can be to submit to Google a sitemap with directories that do not exist, but are served by handleURL. If it is GoogleBot, the app sends textual content that Google will index. If it is a regular browser, it is presented by the corresponding page.

Just got the answer in a previous feature request :

15451 - Add global ShowURL method for console/web targets

[quote]Christian Schmitz on Jan 12, 2011 at 8:55 PM
There is a WebControl.ShowURL to show an URL in the client browser.
It would be good to have a ShowURL method like in the GUI framework, so we can trigger with showurl things on the server.[/quote]

[quote]Greg O’Lone on Sep 8, 2012 at 4:59 AM
I understand your request for Console apps, but in a web project, a Global ShowURL method doesn’t get you anything. Without a connection to a specific Session, the app wouldn’t know where to show the dialog.
[/quote]
That settles it. For the time being, the refresh method through Request.Print seems the only game in town…

You can set the Location header instead of using ShowURL. ShowURL can’t do that for you since it would need “magic” access to the request object.

How would you do that ? JavaScript ?

http://documentation.xojo.com/index.php/WebRequest.Header

Request.Header("Location") = "http://go.somewhere.else/"

[quote=159754:@Thom McGrath]http://documentation.xojo.com/index.php/WebRequest.Header

Request.Header("Location") = "http://go.somewhere.else/"

Thank you.

Just tried with google.com, xojo.com or fontmenu.com and all I get is a white page. I had tried in JavaScript as well to set window.location with the same result.

Seems something is not quite right with the location method.

The HTML Refresh I posted works perfectly, though, I am using it in one of my apps.

Oh, set the status to 301 or 302. 301 indicates that the new url should be permanent, and browsers should update their bookmarks accordingly. 302 is a temporary redirect.

Allright.

This now works :

[code]Function HandleURL(Request As WebRequest) As Boolean
if request.path = “” then return false

Request.Header(“Location”) = “http://xojo.com/
Request.Status = 302

return true
End Function
[/code]

Thanks.