Consider the following structure for a ColdFusion 9 website:
/root
..../MyApp
........../Application.cfc
........../Index.cfm
..../SharedComponents
........../Common.cfc
Within common.cfc contains all common functions that I'd like to share across multiple applications under root.
One of those functions allows me to dynamically create a session name and assign a value.
<cffunction name="CreateSession" access="remote" returntype="any">
<cfargument name="strSessionName" required="yes" type="string">
<cfargument name="strSessionValue" required="yes" type="string">
<cfset Session["#strSessionName#"] = "#strSessionValue#" />
</cffunction>
I call this function through AJAX as I want this session to be created following a JavaScript process.
This is the expression I use in ColdFusion which is then rendered into an actual URL, which is then called through AJAX.
"#Application.Protocol & "://" & CGI.SERVER_NAME#/SharedComponents/common.cfc?method=CreateSession&strSessionName=TestSessionName&strSessionValue=TestValue"
However, when trying to display this newly created session on Index.cfm, there is nothing displayed.
I tried relocating the common.cfc into the folder MyApp, modifying the ColdFusion expression path (shown above) to reflect the new path, and it works no problem.
This leads me to believe that I can't set a session from a function outside of my application's scope (that being the MyApp folder, where Application.cfc is found)
My question is, is there a way to call a function outside of the Application's scope which can still manage the application's sessions?