Solved

Cflocation question

Posted on 2012-03-15
8
713 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 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
problem with finding cfcomponent on cfselect bind 7 91
Splitting up a coldfusion site into 2 separate sites in IIS 3 94
CSS HELP 6 88
Coldfusion retrieve dynamic values 1 36
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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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