Skip to main content
Hedge
Inspiring
December 28, 2014
Question

CF11 cfc gives 500 error but cfm is fine

  • December 28, 2014
  • 2 replies
  • 6596 views

We are testing our cf code which all works fine on a CF9 Windows Server 2008 machine but we are going to migrate to a CF11 Windows 2012 R2 machine. We have a test machine setup and all the code moved over and so far the cfm pages seem to work fine as well as the Application.cfc page but when we call a cfc via AJAX or we visit the cfc methods directly we get a 500.0 error Application could not be found.

Anybody else run into this?

This topic has been closed for replies.

2 replies

Legend
December 30, 2014

I would research how to turn on detailed error reporting, even if it's only temporary. This will better pinpoint the error. IIS by default intercepts all errors, suppresses any details, and spits out an error 500. Another problem I have seen to cause 500 errors is having an error trap the throws a secondary error. To eliminate this possibility I comment out all CFERROR tags and onError application functions.

Anit_Kumar
Community Manager
Community Manager
December 30, 2014

To turn on detailed error reporting,


Uncheck the “Enable HTTP status codes” under Settings inside CF Admin. This will give you CF related error.


Regards,

Anit Kumar

Hedge
HedgeAuthor
Inspiring
December 28, 2014

I am beginning to suspect something changed in how Application.cfc works with sub directories in CF 11. I can take the .cfc I am trying to access out of the sub directory (which has it's own Application.cfc) and put it in the root directory (which has it's own Application.cfc) and it works fine. Any ideas as to why this might be?

Carl Von Stetten
Legend
December 29, 2014

Does one or the other Application.cfc have an onCFCRequest() method in it?  If they both do, is the code inside the method the same?

-Carl V.

Adam_Tuttle
Participating Frequently
April 6, 2015

Now this is the Application.cfc from the sub directory folder named /api that contains my .cfcs so when I try to access the cfc in that sub directory I get that 500 error. If I move the cfc to the root directory the cfc executes like it should.

<cfcomponent

    displayname="Application"

    output="true"

    hint="Handle the application.">

        <!--- Set up the application. --->

        <cfset THIS.Name = "XXXXXX" />

        <cfset THIS.ApplicationTimeout = CreateTimeSpan( 2, 0, 0, 0 ) />

        <cfset THIS.SessionManagement = true />

        <cfset THIS.SessionTimeout = CreateTimeSpan( 0, 2, 30, 0 ) />

        <cfset THIS.SetClientCookies = true />

    <!--- Define the page request properties. --->

    <cfsetting

        requesttimeout="30"

        showdebugoutput="true"

        enablecfoutputonly="false"

        />

    <cffunction

        name="OnApplicationStart"

        access="public"

        returntype="boolean"

        output="false"

        hint="Fires when the application is first created.">

        <CFQUERY NAME="GetAdmin" DATASOURCE="XXXXXX">

            SELECT * FROM AdminOptions

            WHERE ID = 1

        </CFQUERY>

        <cfset APPLICATION.DSN = "XXXXXX" />

        <cfset APPLICATION.debugIPAddress = "XXXXXX" />

        <cfset APPLICATION.debugIPAddress2 = "XXXXXX" />

        <cfset APPLICATION.ScheduledTaskIP = "XXXXXX" />

        <cfset APPLICATION.ScheduledTaskIP2 = "XXXXXX" />

        <cfset APPLICATION.EncryptionKey = "XXXXXX" />

        <cfset APPLICATION.AdminEmail = "XXXXXX" />

        <cfset APPLICATION.NotificationEmail = #GetAdmin.mainEmail# />

        <cfset APPLICATION.SiteTitle = "XXXXXX" />

        <!--- urls --->

        <cfset APPLICATION.SiteURL = "XXXXXX" />

        <cfset APPLICATION.ImageURL = "XXXXXX" />

        <cfset APPLICATION.AttachmentURL = "XXXXXX" />

        <!--- directories --->

        <cfset APPLICATION.BaseDirectory = "XXXXXX" />

        <cfset APPLICATION.VendorUploadsDirectory = "XXXXXX\data\VendorUploads" />

        <cfset APPLICATION.VendorDownloadsDirectory = "XXXXXX\www\downloads" />

        <cfset APPLICATION.ImageDirectory = "XXXXXX\www\product-images" />

        <cfset APPLICATION.AttachmentDirectory = "XXXXXX\www\uploads" />

        <cfset APPLICATION.FeedDirectory = "XXXXXX\data" />

        <cfset APPLICATION.cfcRoot = "#APPLICATION.BaseDirectory#\api">

        <!--- Return out. --->

        <cfreturn true />

    </cffunction>

    <cffunction

        name="OnSessionStart"

        access="public"

        returntype="void"

        output="false"

        hint="Fires when the session is first created.">

        <!--- Define the local scope. --->

        <cfset var LOCAL = {} />

     

        <!---

        Store the CF id and token. We are about to clear the

        session scope for intialization and want to make sure

        we don't lose our auto-generated tokens.

        --->

        <cfset LOCAL.CFID = SESSION.CFID />

        <cfset LOCAL.CFTOKEN = SESSION.CFTOKEN />

     

        <!--- Clear the session. --->

        <cfset StructClear( SESSION ) />

     

        <!---

        Replace the id and token so that the ColdFusion

        application knows who we are.

        --->

        <cfset SESSION.CFID = LOCAL.CFID />

        <cfset SESSION.CFTOKEN = LOCAL.CFTOKEN />

        <!--- Return out. --->

        <cfreturn />

    </cffunction>

    <cffunction

        name="OnRequestStart"

        access="public"

        returntype="boolean"

        output="false"

        hint="Fires at first part of page processing.">

        <!--- Define arguments. --->

        <cfargument

            name="TargetPage"

            type="string"

            required="true"

            />

         

        <!--- Check for initialization. --->

        <cfif StructKeyExists( URL, "reset" )>      

            <!--- Reset application and session. --->

            <cfset THIS.OnApplicationStart() />

            <cfset THIS.OnSessionStart() />      

        </cfif>

    <!---      

    Check to see if the target page is in the web services

    directory. If it is, then we want to delete the OnRequest

    event handler so the web service has access

    --->

    <cfif right(arguments.targetPage,4) is "Orders.cfc">

        <!--- Delete the on request event handler. --->

        <cfset StructDelete( THIS, "OnRequest" ) />

 

        <!--- Delete the on request end handler. --->

        <cfset StructDelete( THIS, "OnRequestEnd" ) />

    </cfif>

        <!--- Return out. --->

        <cfreturn true />

    </cffunction>

    <cffunction

        name="OnRequest"

        access="public"

        returntype="void"

        output="true"

        hint="Fires after pre page processing is complete.">

        <!--- Define arguments. --->

        <cfargument

            name="PageRequestedByUser"

            type="string"

            required="true"

            />

        <cfif (isDefined("SESSION.Admin.ID") AND SESSION.Admin.ID NEQ 0) OR (CGI.REMOTE_ADDR EQ APPLICATION.debugIPAddress) OR (CGI.REMOTE_ADDR EQ APPLICATION.debugIPAddress2)>

     

        <!--- User logged in. Allow page request. --->

        <cfinclude template="#ARGUMENTS.PageRequestedByUser#" />

     

        <cfelse>

     

        <!---

        User is not allowed

        --->

        <cfabort>

     

        </cfif>

        <!--- Return out. --->

        <cfreturn />

    </cffunction>

    <cffunction

        name="OnRequestEnd"

        access="public"

        returntype="void"

        output="true"

        hint="Fires after the page processing is complete.">

        <!--- Return out. --->

        <cfreturn />

    </cffunction>

    <cffunction

        name="OnSessionEnd"

        access="public"

        returntype="void"

        output="false"

        hint="Fires when the session is terminated.">

        <!--- Define arguments. --->

        <cfargument

            name="SessionScope"

            type="struct"

            required="true"

            />

        <cfargument

            name="ApplicationScope"

            type="struct"

            required="false"

            default="#StructNew()#"

            />

        <!--- Return out. --->

        <cfreturn />

    </cffunction>

    <cffunction

        name="OnApplicationEnd"

        access="public"

        returntype="void"

        output="false"

        hint="Fires when the application is terminated.">

        <!--- Define arguments. --->

        <cfargument

            name="ApplicationScope"

            type="struct"

            required="false"

            default="#StructNew()#"

            />

        <!--- Return out. --->

        <cfreturn />

    </cffunction>

<cffunction name="onError">

    <!--- The onError method gets two arguments:

            An exception structure, which is identical to a cfcatch variable.

            The name of the Application.cfc method, if any, in which the error

            happened. --->

    <cfargument name="Except" required = true />

    <cfargument type="String" name = "EventName" required = true />

    <!--- Log all errors in an application-specific log file. --->

<!---  

    <cflog file="#This.Name#" type="error" text="Event Name: #Eventname#" >

    <cflog file="#This.Name#" type="error" text="Message: #except.message#">

    --->

    <!--- Throw validation errors to ColdFusion for handling. --->

    <cfif Find("coldfusion.filter.FormValidationException", Arguments.Except.StackTrace)>

        <cfthrow object="#except#">

    <cfelse>

        <!--- You can replace this cfoutput tag with application-specific error-handling code. --->

        <cfif #CGI.REMOTE_ADDR# IS #APPLICATION.debugIPAddress#>

            <p>Error Event: #EventName#</p>

                <cfif isDefined("SESSION.Member.ID")><p>Member ID: #SESSION.Member.ID#</p></cfif>

                <cfif isDefined("ID")><p>ID Posted: #ID#</p></cfif>

                <p>Error details:<br><cfdump var="#except#"></p>

                <p>Application vars:<br><cfdump var="#Application#"></p>

                <p>CGI vars:<br><cfdump var="#cgi#"></p>

                <p>FORM vars:<br><cfdump var="#FORM#"></p>

                <p>URL vars:<br><cfdump var="#URL#"></p>

            <cfmail TO="#APPLICATION.AdminEmail#" FROM="#APPLICATION.AdminEmail#" SUBJECT="#APPLICATION.SiteTitle# Exception Error" TYPE="HTML">

                <p>Error Event: #EventName#</p>

                <cfif isDefined("SESSION.Member.ID")><p>Member ID: #SESSION.Member.ID#</p></cfif>

                <cfif isDefined("ID")><p>ID Posted: #ID#</p></cfif>

                <p>Error details:<br><cfdump var="#except#"></p>

                <p>Application vars:<br><cfdump var="#Application#"></p>

                <p>CGI vars:<br><cfdump var="#cgi#"></p>

                <p>FORM vars:<br><cfdump var="#FORM#"></p>

                <p>URL vars:<br><cfdump var="#URL#"></p>

            </cfmail>

        <cfelse>      

            <cfmail TO="#APPLICATION.AdminEmail#" FROM="#APPLICATION.AdminEmail#" SUBJECT="#APPLICATION.SiteTitle# Exception Error" TYPE="HTML">

                <p>Error Event: #EventName#</p>

                <cfif isDefined("SESSION.Member.ID")><p>Member ID: #SESSION.Member.ID#</p></cfif>

                <cfif isDefined("ID")><p>ID Posted: #ID#</p></cfif>

                <p>Error details:<br><cfdump var="#except#"></p>

                <p>Application vars:<br><cfdump var="#Application#"></p>

                <p>CGI vars:<br><cfdump var="#cgi#"></p>

                <p>FORM vars:<br><cfdump var="#FORM#"></p>

                <p>URL vars:<br><cfdump var="#URL#"></p>

            </cfmail>

            <cfinclude template="error.cfm" />

        </cfif>

    </cfif>

</cffunction>

</cfcomponent>


Funny you should mention that the issue is inside an /api folder. I'm trying to track down the same problem, except I'm directly accessing an index.cfm (sort of -- onRequest intercepts the request and redirects to CFCs as appropriate -- it's a Taffy API) and I've found that renaming the folder from /api to ... literally anything else... works fine. It's almost as if something in CF has special meaning at /api, like the special /rest mapping does.