473,385 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Please help: Losing Request Scope Variable Values

113 100+
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:

Expand|Select|Wrap|Line Numbers
  1. <cfapplication name="myApp" sessionTimeout="#CreateTimeSpan(0, 0, 20, 0)#" sessionmanagement="yes" clientmanagement="yes">
  2.  
  3. <!--- initialise objects --->
  4. <cfsetting showdebugoutput="no">
  5. <cfimport taglib="taglib" prefix="func">
  6.  
  7. <!--- Create an exclusive lock for the Application scope and
  8.    set a default value for Application.Initialized. --->
  9. <cflock scope="Application" timeout="10" type="exclusive">
  10.   <cfparam name="Application.Initialized" default="false">
  11.   <!--- Create a Request variable to hold the value so you don't
  12.     need a read lock to get it in the next block of code. --->
  13.   <cfset Request.Initialized = Application.Initialized>
  14. </cflock>
  15.  
  16. <!--- If Request.Initialized is false, then the Application scope
  17.    has been reset and the variables need to be set. --->
  18. <cfif NOT Request.Initialized>
  19.   <!--- Create an exclusive Application scope lock and set the values. --->
  20.   <cflock scope="Application" timeout="10" type="exclusive">
  21.     <cfscript>
  22.       Application.Initialized = true;
  23.           <!--- define app level vars --->
  24.     </cfscript>
  25.   </cflock>  
  26. </cfif>
  27.  
  28. <!--- Create a read-only lock for the Application scope
  29.    and duplicate it into Request.App. --->
  30. <cflock scope="Application" timeout="10" type="readonly">
  31.   <cfset Request.App = Duplicate(Application)>
  32. </cflock>
  33.  
  34. <!--- Create a read-only lock for the Session scope
  35.    and duplicate it into Request.Ses. --->
  36. <cflock scope="Session" timeout="10" type="readonly">
  37.   <cfset Request.Ses = Duplicate(Session)>
  38. </cflock>
  39.  
  40. <func:initSecurity> <!--- Instantiates security component --->
  41.  
/taglib/initSecurity.cfm

Expand|Select|Wrap|Line Numbers
  1. <!--- init registration session --->
  2. <cflock scope="Session" timeout="10" type="readonly">
  3.     <cfscript>
  4.         if(NOT isDefined("Request.Ses.security")) {
  5.             Request.Ses.security = createObject("component","com.security");
  6.         }
  7.     </cfscript>
  8. </cflock>

/com/security.cfc


<!--- security component --->
Expand|Select|Wrap|Line Numbers
  1. <cfcomponent >
  2.     <!--- define vars --->
  3.     <cfscript>
  4.         // datasource
  5.         This.dsn = Request.App.dsn;
  6.         // member details
  7.         This.memberid = "";
  8.         This.loggedIn = 0;
  9.         This.password = "";
  10.         This.username = "";
  11.         This.roles = "";
  12.         // referal info
  13.         This.returnURL = "";
  14.     </cfscript>
  15.     <cffunction name="validate" access="public" output="true" hint="validates username and password">
  16.         <cftry>
  17.             <cfquery name="validate" datasource="#This.dsn#">
  18.                 SELECT id,username,password,roles
  19.                 FROM cms_security
  20.                 WHERE username = '#This.username#'
  21.                 AND password = '#hash(This.password)#'
  22.             </cfquery>
  23.         <cfcatch type="database">
  24.             <p>Sorry, cannot validate user.</p>
  25.             <cfabort>
  26.         </cfcatch>
  27.         </cftry>
  28.         <cfscript>
  29.             if (validate.recordCount EQ 1) {
  30.                 This.roles = validate.roles;
  31.                 login();
  32.             }
  33.         </cfscript>
  34.         <!---
  35.         <cfif This.returnURL NEQ "">
  36.             <cfset tmpURL = This.returnURL>
  37.             <cfset This.returnURL = "">
  38.             <cflocation url="#tmpURL#" addtoken="no">
  39.         </cfif>
  40.         --->
  41.     </cffunction>
  42.     <cffunction name="login" access="private" output="false" hint="sets values for user session">
  43.         <cfscript>
  44.             This.loggedIn = 1;
  45.             This.password = "";
  46.         </cfscript>
  47.     </cffunction>
  48.     <cffunction name="logout" access="public" output="false" hint="clears security session, logging user out">
  49.         <cfscript>
  50.             This.memberid = "";
  51.             This.loggedIn = 0;
  52.             This.password = "";
  53.             This.username = "";
  54.             This.name = "";
  55.             This.roles = "";
  56.             // referal info
  57.             This.returnURL = "";
  58.         </cfscript>
  59.     </cffunction>
  60.     <cffunction name="protect" access="public" output="true" hint="checks user list of roles against one allowed role">
  61.         <cfargument name="roles">
  62.         <cfargument name="redirectURL" default="../index.cfm">
  63.         <cfif NOT isDefined("Request.Ses.security") OR Request.Ses.security.loggedIn EQ 0>
  64.  
  65.         <cflocation url="#redirectURL#" addtoken="no">
  66.             <cfdump var="#Request#"> <!--- Has lost security object at this point --->
  67.         </cfif>
  68.         <cfset roleFound = false>
  69.         <cfdump var="#Request.Ses#">
  70.         <cfloop list="#Request.Ses.security.roles#" index="sessionRole">
  71.             <cfif listFindNoCase(roles,sessionRole) GT 0><cfset roleFound = true></cfif>
  72.         </cfloop>
  73.         <cfif roleFound EQ false><cfdump var="#This.roles#"><!---<cflocation url="#redirectURL#" addtoken="no">---></cfif>
  74.  
  75.     </cffunction>
  76.     <cffunction name="protectGeneral" hint="protects page from un-logged-in users">
  77.         <cfargument name="redirectURL" default="../index.cfm">
  78.         <cfif NOT isDefined("Request.Ses.security")>
  79.             <cflocation url="#redirectURL#" addtoken="no">
  80.         </cfif>
  81.         <cfif Request.Ses.security.loggedIn NEQ 1>
  82.             <cflocation url="#redirectURL#" addtoken="no">
  83.         </cfif>    
  84.     </cffunction>
  85.     <cffunction name="findUsername" access="public" output="false" hint="checks to see if username is in db">
  86.         <cfargument name="dsn" required="yes">
  87.         <cfargument name="theUsername" required="yes">
  88.  
  89.         <cftry>
  90.             <cfquery name="get" datasource="#dsn#">
  91.                 SELECT username
  92.                 FROM cms_security
  93.                 WHERE username = '#theUsername#'
  94.             </cfquery>
  95.             <cfreturn get.username>
  96.          <cfcatch type="database">
  97.             <p>Sorry, cannot find username.</p>
  98.             <cfabort>
  99.         </cfcatch>
  100.         </cftry>
  101.     </cffunction>
  102.     <cffunction name="setNewPassword" access="public" output="false" hint="sets new password">
  103.     <cftry>
  104.         <cfquery name="set" datasource="#This.dsn#">
  105.             UPDATE cms_security
  106.             SET
  107.             password = '#hash(This.password)#'
  108.             WHERE id = #This.id#
  109.         </cfquery>
  110.         <cfset This.password="">
  111.     <cfcatch type="database">
  112.         <p>Sorry, setting of new password failed.</p>
  113.         <cfabort>
  114.     </cfcatch>
  115.     </cftry>
  116.     </cffunction>
  117. </cfcomponent>

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
Apr 10 '08 #1
5 6104
acoder
16,027 Expert Mod 8TB
If you're calling <cflocation>, then wouldn't the page have been redirected before you got to cfdump:
Expand|Select|Wrap|Line Numbers
  1. <cflocation url="#redirectURL#" addtoken="no">
  2. <cfdump var="#Request#"> <!--- Has lost security object at this point --->
Apr 10 '08 #2
chromis
113 100+
If you're calling <cflocation>, then wouldn't the page have been redirected before you got to cfdump:
Expand|Select|Wrap|Line Numbers
  1. <cflocation url="#redirectURL#" addtoken="no">
  2. <cfdump var="#Request#"> <!--- Has lost security object at this point --->
Ah heheh, thanks acoder a rather silly mistake!
Jun 11 '08 #3
acoder
16,027 Expert Mod 8TB
No problem! Is it April 11th or June 11th? :p
Jun 11 '08 #4
chromis
113 100+
No problem! Is it April 11th or June 11th? :p
Heheh definately June, something not quite right on this forum!
Jun 11 '08 #5
SMyers
1
May I ask a very basic question to you? Why are you setting request variables when you already have the variables set either in application or session? These two are global for either the period of time the application is running and the user session is active. I strongly suggest refraining from using request variables except when it is specifically for that page and only that page. Do not reinvent the wheel they say when it has already been done ie: do not push global variables to local variable status. Think about how the coldfusion server handles a datasource at the application level vs. at a local variable level. If you guessed it, so much caching going on for even one application. Cannot reuse cached queries for other users of same application. Request and local variables die once you leave that page and that will even generate more caching especially at the datasource, unique caching for every page that runs a query. Just some thoughts for you to think about.
Aug 11 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
16
by: Michele Simionato | last post by:
I have read with interest the recent thread about closures. The funny thing is that the authors are arguing one against the other but I actually agree with all of them and I have a proposal that...
5
by: thomas | last post by:
I'm having a bit of trouble using Request.QueryString(). I want to click on the link to browse all <artist> records in an xml file begining with a particular letter. Any ideas where I'm going...
2
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta...
11
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into...
2
by: Joe Molloy | last post by:
Hi, This isn't a mission critical question but I thought I'dl throw it out there for your feedback as it's a bit curious. I have developed a shopping cart for an application I'm working on...
9
by: Adrian Parker | last post by:
We have a website that works everywhere but on a few PCs on this one site.. Asp.Net 1.1 Server = Windows 2003 Client = XP In the web.config we use - cookieless="false" in the browser settings...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
9
by: TF | last post by:
Hello all, I made a ASP.NET 2.0 site that shows possible "recipes" for paint colors stored in an access dbase. Basically, 1000 colors are stored with specific RGB values in separate columns. A...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.