Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling a File not found error 1

Status
Not open for further replies.

vsimmons

Programmer
Jun 15, 2002
9
0
0
US
I am very new to Cold Fusion, so please forgive me for asking what is probably an extremely simple question. I wanted to know if there is a way to handle a File Not Found error. In my code, I have conditional statements to open certain files depending on the user input using <cflocation>. Is there any way for me to display a nice message to the user if the cflocation url (file), and not re-direct to this file if it is not there?

Thanks!
Vanessa
 
The FileExists() function, when passed a path and filename, will return a boolean true if the file exists and false otherwise.
 
Hi.
[ This is my first post btw :)]

I thought that you might like to try the following.
On IIS5 with CF Server 5 I do this:

In IIS5, go to your website's properties, click 'Home Directory' and then 'Configuration'.
In the 'App Mappings' tab, edit the .cfm item and check the checkbox 'Check that file exists'.

This is the first part. When the file is not found it won't display the ugly Coldfusion file not found error.
It will now show the IIS error.

For the finishing touch, create a directory in your webroot called 'errors' and place a 403.cfm and 404.cfm file.
This way you can create a nice custom error message + insert the error in the database (if necessary).

To activate your custom error pages you must go back to your website properties in IIS and click the 'custom errors' tab.
Select the error that you would like to edit. (In this case : Error 403;15 for the directory browsing denied and 404)

Edit the error mapping and select 'URL'.
Type
/errors/403.cfm
When your users get a 403 or 404 error they will get your custom coldfusion error page.

I hope that this was helpful to you.

Michael Lambert
Gent, Belgium
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top