Frontier Tutorials / Writing an ObjectNotFoundHandler / ONFH Modes of Operation

ONFH Modes of Operation

Your script can return information to mainResponder (and thus to the user) in several ways, as detailed below.

  1. Render and/or return the page content, which mainResponder will insert into the template defined at the lastNomad point in your website.

  2. Redirect to another URL, either inside your site or anywhere else on the internet.

  3. Stuff data directly into the page table, and bypass remaining page rendering processing to avoid using the template.

As we'll see later, you can also use a mixture of these within the same website.

Mode 1: Render and Return the Page Content

When it finds an objectNotFound entry in the page table, and that entry is a script or the address of a script, mainResponder.respond assumes that the script will return the page body text to be inserted in the template.

The script constructs and returns the entire body text for the page. This may include website framework calls to render data from elsewhere in the ODB--even from other websites or guest databases. It could even include calls outside of Frontier--to the file system or an SQL database, for example.

If flRender is TRUE, mainResponder.respond will insert whatever your script returns into the site template, as it does any normal page. If flRender is FALSE but allowScriptsToRun is TRUE, mainResponder.respond will return whatever your script returns as the complete page, without inserting it into the template.

Mode 2: Redirect to Another Page

A redirect is accomplished by calling mainResponder.redirect or by throwing a redirect scriptError (generally faster). For example, to redirect to http://yoursite/notfound404, you could do either of the following from your script:

Your script could either redirect to a fixed, hardcoded URL or calculate the new URL based on the values of lastNomad and remainingPath.

This is the simplest way for the ObjectNotFoundHandler script to work.

Mode 3: Stuff the Page Table

If you want to return something that should not be wrapped in the template and returned as an HTML page (such as binary objects or cascading stylesheet source files), you have to stuff the page table yourself. This is the most powerful approach available for ONFH handlers.

If you take this approach, you must set at least the following entries in the page table:

The actual data to be returned. In a .zip archive, for example, this would be the binary zip file data. In a normal HTML page, this is the page content.

This is the HTTP data type for the content. For a .zip archive, for example, this would be application/x-zip. For a normal HTML page, this is TEXT/HTML (the default content type).

You may also want to set pageTbl^.responseHeaders.["Last-Modified"] (I generally do).

So let's work through some examples.

Tutorial Contents
Writing an ObjectNotFoundHandler
ONFH Overview
ONFH Modes of Operation
About The Examples
Mode 1 Example
Mode 2 Example
Mode 3 Example
Mixing Modes
Misdirected URLs
ONFH Summary
ONFH Applications
ONFH Resources
Bonus: The "Penultimate" Master Script
Bonus: Mode 3 Utility Script
About the Author