Question

Is it possible to render a different page when the requested page does not exist using the OnRequestStart event handler?

function onRequestStart( string targetPage ) {
    // handle another page
} 

if(FileExists(cgi.script_name)){
    include cgi.script_name;
}else{
    // render another page
}

if I use the include directly instead of passing it through onRequestStart, I get an error about missing SESSION

If I don't abort the execution, I get the File not found error. Is there a way to skip trying to find the file and use the onRequestStart event to render a different page?

Was it helpful?

Solution

If you are trying to prevent a 404 of a coldFusion page (e.g. /index2.cfm) where the cfm template doesn't exists you can use onMissingTemplate() in your application.cfc

If the template that causes the 404 isn't something handled by CF (i.e .htm,.html) then you will have to catch it in the webserver using a custom 404 page or possibly a url rewite

OTHER TIPS

Try this insted

OnError()

This fires if an exception gets thrown and is not caught by the controlling code.

Check this article Ben Nadel on application.cfc

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top