Web App with Multiple Pages

This is an extremely basic question and I’m a little embarrassed to ask it but I can’t see an obvious answer in the documentation.

I have a web app with multiple pages so how do I display the correct page based on the URL? I have tried the app’s HandleURL event but that won’t let me show a web page. I thought I might me able to do this at the session level but if I add anything to the end of the URL it never gets to the session but just returns a 404 error.

So, how do I put together a web app that allows different URLs to access separate pages?

Right, so the main way of dealing with this is through the use of hashtags, such as:

http://www.example.com/#page1

If you still want your users to use traditional urls like this

http://www.example.com/page1

Then you’ll need to translate that in HandleUrl and send back a response which has the Location header set to use a hashtag and the HTTPStatusCode set to 301 or 302.

Greg,

Thanks for your response but I’m still not clear how to do this. If I use a #page url how (and where) do I capture it and show the appropriate page?

Are you saying that the # will not cause a 404 error and so I can pick it up in Session.Open?

The HashTagChanged event will fire on the Session object, so you could put code in there like this:

[code]Select Case Self.HashTag
Case “Page1”
WebPage1.Show

Case “Page2”
WebPage2.Show

Case “Page3”
WebPage3.Show

end select[/code]

Greg,

Thanks, I’m getting closer but there is one issue I haven’t resolved yet. If I have an app with 2 pages (page1 and page2) where page1 is the default, I would like to open a fresh browser window and go straight to page2 with a url like:

 http://www.example.com:8080/#page2

The problem I am having is that this just opens page1 with #page2 in the url but it doesn’t fire the HashtagChanged event.

I can’t find a way to go directly to page2 without first having to open page1. Users should be able to bookmark a direct url to any page but I’m haven’t found out how yet. How do I stop the default page from loading and force a different page to be displayed?

[quote=395861:@Peter Lawrence]Greg,

Thanks, I’m getting closer but there is one issue I haven’t resolved yet. If I have an app with 2 pages (page1 and page2) where page1 is the default, I would like to open a fresh browser window and go straight to page2 with a url like:

 http://www.example.com:8080/#page2

The problem I am having is that this just opens page1 with #page2 in the url but it doesn’t fire the HashtagChanged event.

I can’t find a way to go directly to page2 without first having to open page1. Users should be able to bookmark a direct url to any page but I’m haven’t found out how yet. How do I stop the default page from loading and force a different page to be displayed?[/quote]
Can’t you use a URL Parameter for this?

I think I’ve just worked it out. It looks like I have to test the #tag not just in the HashTagChanged event but also in the session’s Open event. I think it will work if I create a page selecting method and call it from both of these event handlers.

Is that the right way to do it?

The issue isn’t so much how I pass the request to the app but how I trap it and I think I’ve finally worked that out. If it’s just a #tag or a query string that is added to the url then the app will accept it ok. If it’s anything else like the traditional /page2 qualities then that will generate a page not found error unless I pick it up in the app’s HandleURL event. But you can’t show pages from there so it needs to be passed down to the session via a redirect.

Either way, what I’ve just discovered (it pays to read the documentation) is that requesting a new page creates a new session and so the session’s open event will fire and I can act on the url there.

[quote=395863:@Peter Lawrence]I think I’ve just worked it out. It looks like I have to test the #tag not just in the HashTagChanged event but also in the session’s Open event. I think it will work if I create a page selecting method and call it from both of these event handlers.

Is that the right way to do it?[/quote]
That’ll work.

Thanks Greg, you were very helpful and I appreciate it.