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

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

Explorer ,
Feb 21, 2012 Feb 21, 2012

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!

2.5K
Translate
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

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.

Translate
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

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".

Translate
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

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

Translate
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

nope, just one lonely application.cfc file

Translate
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

Just for fun, rename it to Application.cfc.

Translate
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

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

Translate
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

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

Translate
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

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

Translate
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
LATEST

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

Translate
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

Do you have any code that could delete it?

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

--

Adam

Translate
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

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

Translate
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