Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cflocation question

Posted on 2012-03-15
8
Medium Priority
?
768 Views
Last Modified: 2012-03-16
Hi,

I am trying to perform a cflocation tag inside of the application.cfc within the onRequestStart function and keep getting an error.

If I leave out the cflocation tag from within the conditional recordcount tag, the pages will open fine. But once I include the cflocation tag, I get an error.

I am trying to run a query on every page to check some details about a User. If the checkuser function comes back with a recordcount greater than 0, i want to direct the user to a specific page no matter where in the site the user was browsing.

I would appreciate it if anyone has a clue why I am getting an error.

Thanks!

Code Sample Below:

<cffunction name="onRequestStart" output="false" returnType="void">

<cfinvoke component="#APPLICATION.somepath#" method="checkUser"  returnvariable="checkUser">
<cfinvokeargument name="User_code" value="#SESSION.User_code#">
</cfinvoke>

         <cfif checkUser.recordcount GT 0>
           
          <cflocation url="../index.cfm" addtoken="no">
                 
            </cfif>


</cffunction>
0
Comment
Question by:CFbubu
8 Comments
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 37728838
make the methods returntype boolean and it will work

<cffunction name="onRequestStart" returnType="boolean" output="false">
  <cfargument name="thePage" type="string" required="true">

<cfinvoke component="#APPLICATION.somepath#" method="checkUser"  returnvariable="checkUser">
<cfinvokeargument name="User_code" value="#SESSION.User_code#">
</cfinvoke>

         <cfif checkUser.recordcount GT 0>
           
          <cflocation url="../index.cfm" addtoken="no">
                 
            </cfif>  
 <cfreturn true>
</cffunction>
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 37728901
what is your error?
and are you eliminating the code from your index.cfm page (the one that you are locating to)?
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 1332 total points
ID: 37729067
dgrafx is making a great point, if I understand it correctly, he is suggesting that you could end up in an infinite loop here.

what you get to index.cfm page, the same checkUser query will again return 0 records (because nothing has changed) and you will again be redirected to index.cfm page (even though you're already there).

You need to add a check to make sure you don't get redirected to the page you're already on.

<cfif NOT cgi.script_name contains "/index">
    .... now checkUser ...

</cfif>
0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 
LVL 25

Accepted Solution

by:
dgrafx earned 668 total points
ID: 37729139
yes - thats what i meant - thank you ...

and since your target page is named index.cfm and all your directories probably have an index.cfm - you need to either specify exactly like if cgi.script_name is not "/index.cfm"
which means the index.cfm file that is in the root directory but will not match an index.cfm file that is in a folder named xyz as it would be "/xyz/index.cfm".
OR you can rename your "special" page - such as "loginspecial.cfm".
your code would then be if NOT cgi.script_name containsnocase "loginspecial.cfm"
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 1332 total points
ID: 37729245
yes, good point.   "contains" is not the best solution there.  I like the idea of using a new file name best.   Even if that file name simply includes the index page (assuming that's the home page perhaps)

loginRequired.cfm ...
   <cfset accessDenied = true>
   <cfinclude template="index.cfm">


Then inside of index.cfm you can test for "accessDenied" and show special messages.  This is one way to reuse the home page but with different messages displayed and also control the redirect from within your application.cfc file..
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 37729317
yup ...

what say you cfbubu?
0
 

Author Closing Comment

by:CFbubu
ID: 37731223
Thanks guys! I was indeed causing an infinite loop....oops!

I wanted to build a way to kick logged-in session users. So I was 'flagging' a row in the user database with a value, than using a query in the onrequest in the application.cfc to check on each page load if the user has been flagged by querying that value. If the user has indeed been flagged, than the user will be directed to a specified page. The issue was that I forgot to destroy the user sessions of a 'flagged' user, and thus this ended up creating the infinite loop error.

I also found the tip about  "<cfif NOT cgi.script_name contains "........"> and the small discussion about it  useful..:)

Also, wanted to extend my well wishes to 'gdemaria' and 'dgrafx' - Hi you guys! Not sure if you remember me. It's been a while since I logged in to get help from this site, but I am happy to see that you are all just as active helping us folks out! You guys did help me answer my questions before. Thanks again for the prompt 'teachings' as always! Much appreciated.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 37731478
Glad it got sorted ...
Have an excellent weekend guys!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question