Solved

Cflocation question

Posted on 2012-03-15
8
726 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 333 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 25

Accepted Solution

by:
dgrafx earned 167 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 333 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

735 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