- 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 · 7 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

7 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>
7 Kevin R // Feb 15, 2011 at 6:59 PM
http://www.bennadel.com/blog/1587-CFM-Templates-And-Remote-CFCs-They-re-All-Just-ColdFusion-Page-Requests.htm
Indeed, however, when I implement OnRequest() my remote HTTP CFC calls fail. Why does it work for Ben Nadel? What am I missing?
I wish to implement one thing which OnRequest() seems ideal for:
(1) Authentication for all requests, which would then create certain variables within the VARIABLES scope.
When I place my authentication CFC into OnRequest() it works perfectly except then my remote access CFCs fail.
When I place it into OnRequestStart() I can't tell if it's working or not because the variables don't exist--I've read a little bit about placing/copying variables into the REQUEST scope, so maybe this is the problem, but I don't understand it very well yet.
Thus,
(1) Why does OnRequest() work in Ben's article I cite above?
(2) Should I be using OnRequestStart() instead? What do I need to make the result variables available?
(3) I need my authentication to run for all HTTP requests: CFM and CFC. Seems I only get CFM's when using OnRequest().
Much thanks for all your posts. Very helpful. CF seems very arcane to me (as a primarily ASP.NET guy), but I'm learning!
I'm using CF8, by the way, so the new OnCFCRequest() isn't an option.
Leave a Comment