11 Replies - 2737 Views - Last Post: 05 July 2010 - 05:06 PM Rate Topic: -----

#1 Guest_Michael*


Reputation:

Application.cfc

Posted 01 July 2010 - 03:56 AM

Can someone explain this?

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.

Is This A Good Question/Topic? 0

Replies To: Application.cfc

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: Application.cfc

Posted 01 July 2010 - 06:46 AM

Application.cfc will overwrite previously invoked Application.cfc variables so in that regard, yes, "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" can happen...but it depends on what you have in that second App.cfc file.

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.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#3 Guest_Michael*


Reputation:

Re: Application.cfc

Posted 01 July 2010 - 07:26 AM

Thanks
Was This Post Helpful? 0

#4 Guest_Michael*


Reputation:

Re: Application.cfc

Posted 01 July 2010 - 08:07 AM

I'm basiclly trying to secure some folder to only logged in people. Is there a way to do this with one application.cfc at the root with out having to put some code in each of those files.
Was This Post Helpful? 0

#5 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: Application.cfc

Posted 01 July 2010 - 12:23 PM

Sure there is. Now, so we're clear, because I don't have your code in front of me I can't give you specific instructions for what code to put in there to accomplish this. That said, what you want to do is to check into how to use the onRequest method of Application.cfc.

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.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Michael*


Reputation:

Re: Application.cfc

Posted 02 July 2010 - 10:11 AM

Thank you very much.
Was This Post Helpful? 0

#7 Guest_Michael*


Reputation:

Re: Application.cfc

Posted 02 July 2010 - 10:56 AM

When you say check and parse the requested URL.
How would you do this. use something like the FindNoCase on the #arguments.targetPage# searching for something like maint in the url?

Thanks
Was This Post Helpful? 0

#8 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: Application.cfc

Posted 02 July 2010 - 10:59 AM

View PostMichael, on 02 July 2010 - 09:56 AM, said:

use something like the FindNoCase on the #arguments.targetPage# searching for something like maint in the url?


Yes.

Can I ask, how much CF experience do you have?
Was This Post Helpful? 0
  • +
  • -

#9 Guest_michael*


Reputation:

Re: Application.cfc

Posted 02 July 2010 - 11:22 AM

Sure,

Just a couple years of playing around. Still have alot of learning to do still. Really enjoying it though. I appreciate your help.
Was This Post Helpful? 0

#10 mpryan73  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 05-February 10

Re: Application.cfc

Posted 02 July 2010 - 12:36 PM

FYI Craig328,

Your link to http://www.eluncher.com has an error on the pages.
Was This Post Helpful? 0
  • +
  • -

#11 mpryan73  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 05-February 10

Re: Application.cfc

Posted 04 July 2010 - 04:18 AM

Thanks Craig328 I was able to combine 4 application.cfc into one and secure what I needed with just this. I wanted to post for someone else to learn from.


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

</cfif>


<cfinclude template="#Arguments.targetPage#">

</cffunction>


Guest_Michael.
Was This Post Helpful? 0
  • +
  • -

#12 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: Application.cfc

Posted 05 July 2010 - 05:06 PM

View Postmpryan73, on 02 July 2010 - 11:36 AM, said:

FYI Craig328,

Your link to http://www.eluncher.com has an error on the pages.


Thanks. It's in the process of being moved from a smaller server to a larger one.

Should be completed by Wednesday. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1