ColdFusion

Application.cfc in ColdFusion 8

March 20, 2009

In my studies for certification commented an Application.cfc, and now made available for you.

source: Adobe Live Docs

I created one pages cfm to test the executions, with the following code:

<!--- All the variable maids during onRequestStart will be seen in the pages requested --->
<cfoutput>#Variables.start#</cfoutput>, now am in CFM.<br />

<!--- All the variable maids during onRequest will be seen in the pages requested --->
<cfoutput>#Variables.OUT#</cfoutput>, now am in CFM.<br />

<!--- content of the pages cfm --->
It is is to pages of the pcsilva<br />


<!--- All the variable maids during request will be seen in onRequestEnd --->
<cfset Variables.IN = "I was in page.cfm" >

Soon after I created a second pages (404.cfm), for use in the method onMissingTemplate, with simple content.

And now Application.cfc

<!--- The windows is case-INsencitive, but both words are private Application.cfc and application.cfc.
Linux is case-sensitive, he does not answer well for application.cfc, but both words are private Application.cfc and application.cfc.
And now Application.cfc --->

<cfcomponent>

<!--- name of the application --->
<cfset this.name = "Anotacoes_applicationcfc" >

<!--- time of life of the application --->
<cfset this.applicationTimeout = createTimeSpan(0,0,0,1) >

<!--- time of life of the session --->
<cfset this.sessiontimeout = createTimeSpan(0,0,0,1) >

<!--- it allows variables in the scope client --->
<cfset this.clientmanagement = "yes" >

<!--- it allows variables in the scope session --->
<cfset this.sessionmanagement = "yes" >

<!--- it allows to try creating cookies, sends CFID and CFTOKEN, to the client --->
<cfset this.setClientCookies = "yes" >

<!--- cookie for domain, an only CFID/CFTOKEN for several sub-domains of the same domain --->
<cfset this.setDomainCookies = "no" >

<!--- it prevents attacks, see/add expressions in the file neo-security.xml --->
<cfset this.scriptProtect = "all" >

<!--- it addresses login for the scope attributing (session or cookie) --->
<cfset this.loginstorage = "session" >

<!--- To use this property you should enables her
in ColdFusion Administrator > Settings > Enable Per App Settings --->

<cfset this.mappings["MyMapping1"]="C:\ColdFusion8\wwwroot\app1">
<cfset this.mappings["MyMapping2"]="C:\ColdFusion8\wwwroot\app2">

<!--- To use this property you should enables her
in ColdFusion Administrator > Settings > Enable Per App Settings --->

<cfset this.customtagpaths = "C:\ColdFusion8\wwwroot\taglib,C:\ColdFusion8\wwwroot\customtags">

<!--- file names list that ColdFusion should interpret
as it pages standard, generally the site has a standard file
pre-defined in the configuration, this variable is not required,
but you can create your standard file namein ColdFusion Administrator > Settings > Enable Per App Settings --->

<cfset this.welcomeFileList = "index.cfm,default.cfm,index.cfml,default.cfml,index.cfr,default.cfr" >

<!--- it determines if in the initiate of an answer JSON will contain prefix, this prevents attacks cross-site
(ColdFusion Administrator > Settings > Prefix serialized JSON with) --->

<cfset this.secureJSON = true >

<!--- ColdFusion Administrator > Settings > Prefix serialized JSON with, it contains the standard value (this.secureJSON should be true so that caracter be used) --->
<cfset this.secureJSONPrefixx = "--" >



<!--- Event shot at the beginning of the application --->
<cffunction name="onApplicationStart" output="true" returntype="boolean">

<!--- You can emit messages to the client from the interior of this method --->
I am onApplicationStart <br />

<!--- The return owes always be true so that the requisition/application continues --->
<cfreturn true>

</cffunction>




<!--- Event shot in the terminus of the application,
This event only will occur when the application remain
inactive by the a period of certain time's as
time of life of the application (this.applicationTimeout),
This event does not shoot the method onSessionEnd,
This event ca not access the scopes Session and Request --->

<cffunction name="onApplicationEnd" output="true" returntype="void">

<!--- The past argument by the server is the scope application --->
<cfargument name="AppScope" required="true" type="struct" >

<!--- You WILL NOT MANAGE to emit messages to the client from the internally of this method,
that only will be possible there is an invoke of this method for a request --->

I am onApplicationEnd <br />

<!--- to register the execution of this event registers in log --->
<cflog file="#This.Name#" type="Information" text="onApplicationEnd" >

<!--- method does not return value --->

</cffunction>




<!--- Event shot at the beginning of the session --->
<cffunction name="onSessionStart" output="true">

<!--- You can emit messages to the client from the interior of this method --->
I am onSessionStart <br />

<!--- method does not return value --->

</cffunction>




<!--- Event shot in the terminus of the session --->
<cffunction name="onSessionEnd" output="true" returntype="void">


<!--- The past argument by the server is the scope session --->
<cfargument name="SessionScope" required="true" type="struct" >


<!--- The past argument by the server is the scope application --->
<cfargument name="AppScope" required="true" type="struct" >


<!--- You WILL NOT MANAGE to emit messages to the client from the interior of this method,
that only will be possible there is an invoke of this method for a request --->

I am onSessionEnd <br>


<!--- to register the execution of this event registers in log --->
<cflog file="#This.Name#" type="Information" text="onSessionEnd">


<!--- method does not return value --->


</cffunction>




<!---
Event shot at the beginning of the requisition,
This event is ideal to include test to authenticate
and autenticador, like cflogin
--->

<cffunction name="onRequestStart" output="true">


<!--- file name asked by the client, cgi.script_name --->
<cfargument name="targetPage" required="true" type="string" >


<!--- You can emit messages to the client from the interior of this method --->
I am onRequestStart<br>


<!--- Variable that will be seen in the pages asked --->
<cfset Variables.start = 'I was in the Application.cfc (onRequestStart)' >


</cffunction>






<!--- shot event is equivalent the requisition
it is recommend that this method TO DO NOT BE used to CFC?WSDL,
Flash Remoting, event gateway --->

<cffunction name="onRequest" output="true">


<!--- file name asked by the client, cgi.script_name --->
<cfargument name="targetPage" required="true" type="string" >


<!--- You can emit messages to the client from the interior of this method --->
I am onRequest<br>


<!--- Variable that will be seen in the pages asked --->
<cfset Variables.OUT = 'I was in the CFC (onRequest)' >


<!--- Inclusion of the pages asked by the client --->
<cfinclude template="#arguments.targetPage#">


<!--- Variable that was created in the pages asked --->
<cfoutput>#Variables.IN#</cfoutput>, I was in the CFC (onRequest).<br>


<!--- method does not return value --->


</cffunction>





<!--- Event shot in the terminus of the requisition --->
<cffunction name="onRequestEnd" output="true">


<!--- file name asked by the client, cgi.script_name --->
<cfargument name="targetPage" required="true" type="string" >


<!--- You can emit messages to the client from this method on --->
I am onRequestEnd<br>


<!--- Variable that was created in the pages asked --->
<cfoutput>#Variables.IN#</cfoutput>, I was in the CFC (onRequestEnd).<br>


</cffunction>






<!--- This event is shot when it occurs a Mistake 404
It is not allowed cflocation use, GetPageContext().forward(), or
GetPageContext().include(). Use a cfinclude
The execution of this method aborts the execution of the methods OnRequestStart, OnRequest, OnRequestEnd
A mistake in this method shoots the method onError --->

<cffunction name="onMissingTemplate" output="true">


<!--- file name asked by the client, cgi.script_name --->
<cfargument name="targetPage" required="true" type="string" >

<!--- You can emit messages to the client from this method on --->
Eu sou o onMissingTemplate<br>

<cfinclude template="404.cfm" >

<!--- The return owes always be true so that the requisition continues,
but onRequestStart, onRequest, onRequestEnd not will be executed --->

<cfreturn true >


</cffunction>


<!--- this event is shot when it occurs a mistake within ones of the methods,
except for the own method --->

<cffunction name="onError" output="true">


<!--- The past argument by the server is the scope cfcatch --->
<cfargument name="Exception" required="true" >


<!--- Name of the method where occurred the mistake --->
<cfargument name="EventName" required="true" type="string" >


<!--- You can emit messages to the client to leave
from this method, when the mistakes occur inside the methods onApplicationStart,
onSessionStart, onRequestStart, onRequest, or onRequestEnd --->

I am onError<br>


<!--- to register the execution of the mistakes occurred in the methods
onApplicationEnd, onSessionEnd registers in log --->

<cflog file="#this.name#" type="Information" text="onError" >

<!--- method does not return--->

</cffunction>




</cfcomponent>

OnSessionEnd's Executions and of OnApplicationEnd will be registered in the same name log of the application, in the folder of the logs of ColdFusion.

Test all the possibilities, and it go studying for method, see the execution and read script, new execution and read the comments, do new test based on comments.



Send

Share your view

Add Comment

Subscribe

Enter your email address to subscribe to this blog.

Digitrum Servers Powered by Blogcfc 5.9.2.002