Scheduled Tasks and Anonymous Access in ColdFusion 11

ColdFusion Scheduled Task setup form

I have been converting applications from ColdFusion 8 to CF 11 over the last several months, and some of the challenges have been quite a bit more daunting than this one. Even so, I felt this was worth mentioning.

After copying all the code for my most recent upgrade candidate from the old server to the new one and setting it up in IIS, I proceeded to set up the CF Scheduled Tasks on the new server.

One of the tasks that I set up runs under a blank user name. In order for that to work, you have to make certain that several settings related to authentication are set properly in IIS. First of all, if the app as a whole runs under anything other than Anonymous Authentication (such as Windows Integrated Authentication or Forms Authentication), your Scheduled Task URL will have to be inside a folder that has Anonymous Authentication enabled, even if it’s turned off for the rest of the app.

Secondly, you have to make sure that the “jakarta” virtual folder that is set up during IIS configuration of the website also has Anonymous Authentication enabled.

Having Anonymous Authentication disabled on the jakarta folder will cause no end of irritation if you don’t have the output of the URL sent to a file, as neither the application log file nor the Security log in Windows Event Viewer will tell you exactly why the task is failing. If you send output to a text file, you can rename that text file with an HTML extension (I’m still not sure why Adobe doesn’t just allow output as HTML for this…) and then see more clearly why your task was failing.

IIS authentication error

So set your authentication properties correctly to avoid this frustration!

Windows Disks Keep Filling Up with Small Log Files

Windows 2012 logo

I noticed that a Windows server I use for development with Visual Studio 2013 Ultimate had begun filling its system drive with log files in C:\Windows\Temp for no apparent reason.

The initial response of our infrastructure group was to simply delete the log files on a weekly basis, as no one could find the cause of the problem. Since this issue was apparently in the purview of that group, I let this solution stand initially. However, as I feared, the problem became worse and the server began crashing on a weekly basis.

The log files had many messages that contain “Product: Microsoft Visual Studio Professional 2013 — Configuration completed successfully.”

I wasn’t sure that the log files were the cause of the crashes, but it became apparent that the two were likely connected when I saw many similar errors in the Application log under Event Viewer: “Detection of product ‘{9C593464-7F2F-37B3-89F8-7E894E3B09EA}’, feature ‘Testing_Tools_for_Pro_x86_enu’, component ‘{55E69908-5292-4B15-A56D-822A6050848F}’ failed. The resource ” does not exist.”

Application log entry

There are a couple of fixes that should be applied here. The first is very simple. In all likelihood, a folder named “Microsoft.NETFrameworkURTInstall_GAC” is missing from the %SystemRoot% (usually C:\Windows) folder.

If this folder is, in fact, missing, add it using either
1.an elevated Command Prompt with this command:
mkdir %SystemRoot%Microsoft.NETFrameworkURTInstall_GAC
or
2. PowerShell:
mkdir $env:SystemRoot\Microsoft.NETFrameworkURTInstall_GAC

The second fix is to repair Visual Studio 2013 in the Control Panel.

Open Control Panel, open Programs and Features, select Microsoft Visual Studio 2013 [Professional/Ultimate/etc.], click Change, and click Repair on the VS splash screen.

In most cases, this will fix your problem.

Sources:
Visual Studio 2013 continuously repairs producing many small log files

Adding Lines to the Beginning and Ending of Files Using PowerShell

Stack Overflow PowerShell question

In dealing with an application with which I had little familiarity, I discovered that troubleshooting an app (in this case developed using ColdFusion) where many of the source code files are “included” dynamically can be difficult – especially when JavaScript scripts are combined that have functions with identical names.

Because so many of the functions were not only identically named, but also similarly constructed, I decided to add commented identifiers to the beginning and ending of each JS file.

This could be done in a number of ways, but given my recent forays into using PowerShell scripts, I chose that route again.

Stack Overflow PowerShell question
Stack Overflow and Google – developers’ best friends.

After some Googling and a brief visit to Stack Overflow, I learned about the two PowerShell “cmdlets” that would be most useful here: Set-Content and Add-Content.

The text of the script is below. What this script does is recursively search through the file path in line 1, choosing only files that have the extension after the filter switch (.js in this case). Looping through these file names, each file is read into memory (using Get-Content). The root of the file is then removed with the first replace command, and for aesthetics, I chose to change backslashes into forward slashes with the second one (lines 4 and 5). Notice that backslashes must be escaped by using an extra backslash, whereas forward slashes are not escaped. Also, in case you’re wondering, the backtick-n (`n) is the newline character in PowerShell. The Set-Content cmdlet is used to add the “$newline” string and then the original file content. The Add-Content cmdlet is then used to add the line marking the end of the file.

Get-ChildItem "C:\Folder\Subfolder" -recurse -Filter *.js | `
Foreach-Object{
    $content = Get-Content $_.FullName
    $fullname = $_.FullName -replace "C:\\Folder\\Subfolder", ""
    $fullname = $fullname -replace "\\", "/"

    $newline = "// file: " + $fullname + " `n"
    Set-Content $_.FullName -value $newline, $content
    $endline = "// end of file: " + $fullname + " `n"
    Add-Content $_.FullName $endline
}