Wednesday, September 18, 2013

CF10 expandPath() issue with IIS virtual directories

First of all, allow me to preface this post with the fact that I am not advocating the use of IIS virtual directories in lieu of ColdFusion mappings.  That is a separate legacy environment issue we're planning on addressing.

With that disclaimer out of the way, the issue that we were experiencing is with the expandPath() function not resolving properly for missing files/directories that use an IIS virtual directory as the mapping [i.e., expandPath("/myMapping/myMissingDirectory")].  This was a non-issue in ColdFusion 9.

This issue was present in ColdFusion 10 with ColdFusion mappings, but it apparently was fixed in the final build of ColdFusion 10 (I verified on my version which is running update 11).

The behavior that is happening is that if a file/directory in expandPath() does not exist CF is resolving the root mapping as starting at the root of your site directory (again, this is currently only an IIS VD issue).

For example, if you have a site directory of C:/inetpub/wwwroot/mySite and have an IIS virtual directory of myMapping that points to C:/inetpub/wwwroot/myMapping and you try to use expandPath() on a file/directory that does not exist then CF resolves the path as C:/inetpub/wwwroot/mySite/myMapping instead of C:/inetpub/wwwroot/myMapping as I would expect.

The fix for this is to use expandPath() on a directory you know will exist and append the rest of the path as in expandPath("/myMapping") & "/myMissingDirectory".

Since people should really be using ColdFusion mappings within CF code, I don't feel like a ticket should be created; but what do you all think?

4 comments:

  1. We just upgraded to CF10 and are also experiencing this problem. Although it seems to be an issue even if the specified virtual directory path is completely valid.

    Also, there are valid reasons for using an IIS virtual directory as opposed to a CF mapping (like if the directory contains HTML and/or image files because they are served directly via IIS and don't get processed by ColdFusion).

    ReplyDelete
    Replies
    1. That's weird you're still having issues with a valid directory path. Have you been able to resolve it now?

      Good point about HTML files and image files. By default they are served from IIS, but you can configure the application server to serve them up instead, although I don't know anyone who does that. Point taken!

      Delete
    2. The only resolution I could find was to create a CF mapping that corresponded to the IIS virtual directory.

      In a way this behavior makes sense to me... how is CF supposed to know about VDs that are defined in IIS? I assume ExpandPath() is just looking at the filesystem and therefore wouldn't know about the VDs unless there was some way that IIS provided this info to CF. But this theory doesn't explain how it was actually working with earlier versions of CF/IIS.

      Delete
    3. I'm assuming it knows about them when the sites are registered and configured with the IIS Connector when installing CF. I admittedly am not totally sure either how it works, but that's my guess.

      Delete