• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

OnRequestStart doesn't always run on request start?!?

Explorer ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

I have an application.cfc file in my root directory with the following line:

<cffunction name="onRequestStart">

     <cfif NOT IsDefined("Session.PortalPermissions")>

          <cfset Session.PortalPermissions = 0>

     </cfif>

</cffunction>

however i occasionally receive this error report which is emailed to me.  The error is never generated from an included template, not the application.cfc file itself:

Element PORTALPERMISSIONS is undefined in SESSION.

Template: C:\Inetpub\mysite\secure\utilities\tinymce\index.cfm

I'm wondering how it's possible to receive thie error message if the onRequestStart method is called before my template that uses the Session.PortalPermission.

Thanks!

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

It always runs, but it doesn't run *first*. First it runs any code at the top of Application.cfc, then onAppStart if required, then onSessionStart, *then* onRequestStart. If you reference the variable in any of those before onRequestStart, you'll get an error.

Plus don't use isDefined - use structKeyExists as it's more specific.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

Thanks for the reply Owain but the error IS occuring on a file that is included from my index.cfm file, it allows application.cfc to process fully before making the include.  Sorry for the typo in my original post, omit the word "never".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

Plus don't use isDefined - use structKeyExists as it's more specific.

What's more, it has (had?) a habit of giving false-positives on session variables.

As for the OP's situation... checking the existence of a session variable in onRequestStart() seems like bung logic to me.  Set it in onSessionStart, then you know it's there for the life of the session.  What you're doing here seems like a bandaid for some other issue which ought to be dealt with differently.

Do you have any code that could delete it?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

nope, just one lonely application.cfc file

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

Just for fun, rename it to Application.cfc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

renamed, I'll report back if that fixes it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

The OP is one windows.  This will make no difference.  That said, the name of the file is supposed to be Application.cfc (not application.cfc) so it's slightly preferential - from a completist POV - to get it right.

I think the problem is most likely gonna be the isDefined() call, rather than using structKeyExists().

Or some vagary of the code that the OP's not told us about 😉

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

nope, just one lonely application.cfc file

No <cfapplication> tags which might be referencing a different application name?  Session variables are application-specific as well as being session-specific.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

LATEST

Sorry for the late reply, no <cfapplication> tags and no other code that would be deleting session variables.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

Do you have any code that could delete it?

You've not commented on this.  What other code writes to that variable?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2012 Feb 21, 2012

Copy link to clipboard

Copied

Is there any other Application.cfc or Application.cfm on the ancestor path between the file being requested which is generating the error, and the Application.cfc in the root?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation