Question

I am just considering a scenario where someone might give Application.cfc in a url. I know this will not work as it is reserved by ColdFusion engine and user will see an error.

Is it possible to redirect user in such scenario?

Was it helpful?

Solution

I just successfully caught it with a site-wide error handler. Is that a viable solution for you?

Small update, figured this out:

<cftry>
    <cfif error.Message EQ "Invalid request of Application.cfm, Application.cfc, or OnRequestEnd.cfm file.">
        <cflocation url="#getContextRoot()#/#getDirectoryFromPath(error.Template)#">
    </cfif>
    <cfcatch>that didn't work</cfcatch>
</cftry>

OTHER TIPS

I think CF intercepts the call to application.cfc, application.cfm and onrequestend.cfm at a position where you can grab the error.

I just did some testing on one of my coldfusion development sites and brought the application.cfc up a parent folder before the defined IIS website home folder and tried to call the file. It returned a 404 error for file not found. Since coldfusion searches up to the root folder to find the file, it will still find your application.cfc file even though its not in an IIS accessible folder. IIS will turn your 404 error for direct requests.

Handling your 404 error maybe the solution.

I assume this would also be a solution for non windows server environments as well.

Well: you should handle this sort of error the same way you handle any uncaught error on your website: leave it to the onError() handler / <cferror> code / site-wide error template. As you're using Application.cfc, onError() is the best approach here.

This sort of error doesn't need special handling, but unhandled errors of any type should be dealt with appropriately. If you're not doing this (it sounds like you're not), you ought to be.

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