Hi there,
I've recently been updating a site to use locking on application level variables, and I am trying to use a commonly used method which copies the application struct into the request scope. Application variables are then accessed in this manner Request.App.<Var>.
To begin with I had a simple functioning login system inside a subdirectory named admin, this subdirectory had it's own application.cfm, I wasn't sure whether to duplicate the method i used in the root application.cfm so i removed the admin/application.cfm and declared the vars i wanted in the root application.cfm.
Everything worked fine and I was able to log into the admin section as before, only when i tryed to navigate to a page in admin section my security component which deals with logging in etc, lost it's variable values.
I'm not sure why it is losing the information, and was hoping someone could point me in the right direction please?
Here is the relevant code:
/Application.cfm:
-
<cfapplication name="myApp" sessionTimeout="#CreateTimeSpan(0, 0, 20, 0)#" sessionmanagement="yes" clientmanagement="yes">
-
-
<!--- initialise objects --->
-
<cfsetting showdebugoutput="no">
-
<cfimport taglib="taglib" prefix="func">
-
-
<!--- Create an exclusive lock for the Application scope and
-
set a default value for Application.Initialized. --->
-
<cflock scope="Application" timeout="10" type="exclusive">
-
<cfparam name="Application.Initialized" default="false">
-
<!--- Create a Request variable to hold the value so you don't
-
need a read lock to get it in the next block of code. --->
-
<cfset Request.Initialized = Application.Initialized>
-
</cflock>
-
-
<!--- If Request.Initialized is false, then the Application scope
-
has been reset and the variables need to be set. --->
-
<cfif NOT Request.Initialized>
-
<!--- Create an exclusive Application scope lock and set the values. --->
-
<cflock scope="Application" timeout="10" type="exclusive">
-
<cfscript>
-
Application.Initialized = true;
-
<!--- define app level vars --->
-
</cfscript>
-
</cflock>
-
</cfif>
-
-
<!--- Create a read-only lock for the Application scope
-
and duplicate it into Request.App. --->
-
<cflock scope="Application" timeout="10" type="readonly">
-
<cfset Request.App = Duplicate(Application)>
-
</cflock>
-
-
<!--- Create a read-only lock for the Session scope
-
and duplicate it into Request.Ses. --->
-
<cflock scope="Session" timeout="10" type="readonly">
-
<cfset Request.Ses = Duplicate(Session)>
-
</cflock>
-
-
<func:initSecurity> <!--- Instantiates security component --->
-
/taglib/initSecurity.cfm
-
<!--- init registration session --->
-
<cflock scope="Session" timeout="10" type="readonly">
-
<cfscript>
-
if(NOT isDefined("Request.Ses.security")) {
-
Request.Ses.security = createObject("component","com.security");
-
}
-
</cfscript>
-
</cflock>
/com/security.cfc
<!--- security component --->
The admin section has the following structure:
/admin/index.cfm
/admin/display/login.cfm - Login form
/admin/display/dologin.cfm - Shown on login
/admin/news/index.cfm
/admin/news/display/add.cfm
/admin/news/display/edit.cfm
/admin/news/display/view.cfm
I wasn't sure where to put the code to test the user so i have tryed in the index.cfm and the display/* files.
This code checks for the logged in user:
[CODE"]<cfset Request.Ses.security.protect("staff")>[/code]
The security object and it's variables exist when the /admin/index.cfm page is run I have checked with cfdump.
It's just when i try to access one of the function pages
/admin/news/index.cfm?action=add
the values stored in the security object get reset somehow.
Has anyone any ideas?
Thanks,
Chromis