- Implement this method only if the following are true:
- The directory, and any subdirectories affected by this Application.cfc contain CFM files and do not contain any CFC files that are intended to be accessed as web services, using Flash Remoting, or using an event gateway.
- You want to intercept the request and process it in a special way.
Application.cfc - onRequest() and CFCs
April 7, 2005 · 6 Comments
Now that people are starting to use Application.cfc they are starting to trip over a gotcha with onRequest(). Read the LiveDocs reference for the onRequest() method!
Or, if you're too lazy to read the documentation (as if!), I'll quote the relevant paragraph here for you:
Tags: coldfusion

6 responses so far ↓
1 Derek V. // Feb 19, 2009 at 11:02 AM
If you happen to get this, I would appreciate and reply.
I have a root Application.cfc (x:\projectname\) and have successfully extended that into another folder (x:\projectname\ws\) and use cfNTauthenticate to control access there. I am adding a webservice to this application and would like to extend the root Appliation.cfc so I can use application variables. When extending an Application.cfc file, I understand that if I omit a method, it simply inherits the root. If I include a method, you basically start it from scratch - unless I have that wrong to begin with. But if I include the OnRequstMethod() then the web service (as stated above) is not able to execute. I have this working with Application.cfm but wonder two things.
a.) Can I define the onRequest method in my (x:\projectname\ws\) Application.cfc but void it out some how, so the web service will not inherit the root CFC and then work?
b.) Or, can I simply extend the root CFC application scope variables in the (x:\projectname\ws\) Application.cfm?
Thanks for any help you might have here.
2 Sean Corfield // Feb 19, 2009 at 11:14 AM
What you need to do in your sub-Application.cfc is inside onRequestStart(), use structDelete() on THIS and VARIABLES scope to remove onRequest(). Ray Camden blogged this some time ago (he credits the tip to me - I was just slow to blog it).
3 Derek V. // Feb 19, 2009 at 11:15 AM
Putting
<cfscript>
structDelete(variables,"onRequest");
structDelete(this,"onRequest");
</cfscript>
in my extended Application.cfc.
(sorry)
4 Sean Corfield // Feb 19, 2009 at 1:08 PM
5 Stefan // Feb 26, 2009 at 11:45 AM
<cfif listLast(arguments.targetPage,'.') is 'cfc'>
<cfset StructDelete( THIS, "OnRequest" )>
</cfif>
It works for me, but maybe it has some evil side effects that I will learn later.
6 Sean Corfield // Feb 26, 2009 at 12:32 PM
Application.cfc:
<!--- ensure CFC / Web Service / Flex Remoting calls are not intercepted --->
<cfif right(arguments.targetPage,4) is ".cfc">
<cfset doCompile = false />
<cfset structDelete(variables,"onRequest") />
<cfset structDelete(this,"onRequest") />
</cfif>
Leave a Comment