11 Replies - 3056 Views - Last Post: 05 July 2010 - 05:06 PM
Posted 01 July 2010 - 03:56 AM
I'm using applicaion.cfc in root and in some applicaion.cfc subfolders for Login etc.
If I create a Session variable at the root level it doesn't seem to be available in sub folder that have a seperate application.cfc.
I currently all applicaion.cfc with the same name set with This.Name.
Is this to be expected. Will this cause one to over right the other?
I'm trying to login at the root as an admin and have rights to all subs.
Replies To: Application.cfc
Posted 01 July 2010 - 06:46 AM
Folks new to App.cfc want to use it in much the same way as App.cfm was used by setting them at multiple levels of the app's tree structure. The CF engine will recognize and execute Application.cfc files at any level it encounters them but they act somewhat differently than the old Application.cfm files. The methods in App.cfc, for instance, are invoked per certain events whereas Application.cfm was really nothing more than a page that gets automatically included and slotted into first in line for every page request.
Your best bet is to look at your app's structure then at your root directory's Application.cfc file, see if you can modify that to work for you and dump all the other Application.cfc files. They'll do nothing more than sow confusion and errors if you're not 100% sure of what you're doing.
Posted 01 July 2010 - 08:07 AM
Posted 01 July 2010 - 12:23 PM
onRequest works almost exactly like Application.cfm used to work in that it is executed before every page request. So, what you'd want to do is check and parse the requested URL and only allow the request to continue if the user doing the requesting is logged in. Since your original question was about session variables I'm assuming that you're setting something like a "isLoggedIn" session variable or something similar so that you have a variable you can reference that is particular to each user's session that relates their current login status.
Ben Nadel has a great example of what you can do with the onRequest scope here. Put simply, because it's a component method it has an arguments scope as well. One of those arguments is predefined by the CF engine and that's arguments.targetPage. All that is is the requested URL. Well, if you have the requested URL as a string, you can parse the string for where the user is wanting to go, versus their login status (in your case but you can qualify their access to the requested page any way you like). If they pass you can simply send them on their way (<cfinclude template="#arguments.targetPage#">) and if they fail you can handle that failure however you like. CFABORT it with a message, send them back to the home page of the site, send them to a "you don't have access to this page" kind of error page...however you wish.
Check out that link and you should be able to handle any incoming page request however you need to with just the one Application.cfc and just the one onRequest method.
Posted 02 July 2010 - 10:56 AM
How would you do this. use something like the FindNoCase on the #arguments.targetPage# searching for something like maint in the url?
Posted 02 July 2010 - 10:59 AM
Posted 04 July 2010 - 04:18 AM
<cffunction name="onRequest" returntype="void">
<cfargument name="targetPage" type="String" required=true/>
<cfif #FindNoCase("/maint/",ARGUMENTS.TargetPage)# GT 1 AND #Session.Access# NEQ #Session.TeamID#>
<cflocation url="/BBQ/Login/UserLoginForm.cfm" addtoken="no">
Posted 05 July 2010 - 05:06 PM
Thanks. It's in the process of being moved from a smaller server to a larger one.
Should be completed by Wednesday.