Setting the physical file path of an application with ColdFusion

Hopefully this tip will help someone down the road too, or maybe someone can enlighten me as to the "right" way to code for the physical file path of an application.

I was setting the following code in the OnApplicationStart() method to set the application's physical file path (http://mydomain.com/myApplication):

<cfset application.rootpath = expandPath('./')>
The application uses index.cfm as a "controller" (i.e.index.cfm?disp=thispage) so I THOUGHT it would set the path relative to the root of the application (C:\inetpub\wwwroot\mydomain\myApplication)

Well, it does...MOST of the time....I still haven't gotten to the bottom of it, but sometimes the rootpath would get set to nested directories (C:\inetpub\wwwroot\mydomain\myApplication\middle\). I can only assume that the application would sometimes reinit when it was in the middle of processing something in the "middle" directory.

Long story short, I'm about to deploy this code fix to (hopefully) resolve the problem:

<cfset application.rootpath = "#expandpath('/')##application.applicationname#\"> .
The application.applicationname is the same as the "myApplication" directory, so I'm hopeful that this will work....at least my three test runs worked..lol

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002. Contact Blog Owner