Copy link to clipboard
Copied
Trying to get a site login set up and I keep getting the above error. I have enabled session vars in the CF admin, and have used sessionmanagement in my cfapplication. Not sure what I've done wrong.
<cfapplication name="myApp" sessionmanagement="yes" setclientcookies="yes" sessiontimeout="#CreateTimeSpan(0,1,0,0)#">
<!--- Now define that this user is logged out by default --->
<CFPARAM NAME="session.allowin" DEFAULT="false" />
<CFPARAM NAME="session.userName" DEFAULT="" />
<!--- Now if the variable "session.allowin" does not equal true, send user to the login page --->
<!--- the other thing you must check for is if the page calling this application.cfm is the "login.cfm" page and the "Login_process.cfm" page since the Application.cfm is always called, if this is not checked the application will simply Loop over and over. To check that, you do the following call --->
<cfif session.allowin neq "true">
<cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
<cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "login_process.cfm">
<cfelse>
<!--- this user is not logged in, alert user and redirect to the login.cfm page --->
<script>
alert("You must login to access this area!");
self.location="login.cfm";
</script>
</cfif>
</cfif>
Any help would be greatly appreciated.
It's far from sublime I'm afraid. You simply seem to have used the cfapplication tag in Application.cfc. To be clear, the 2 alternatives are:
Application.cfm
<cfapplication name="myApp" applicationtimeout="#CreateTimeSpan(1,0,0,0)#" sessionmanagement="yes" setclientcookies="yes" sessiontimeout="#CreateTimeSpan(0,1,0,0)#">
or else
Application.cfc
<cfcomponent>
<cfscript>
this.name = "myApp";
this.applicationTimeout = "#createTimespan(1,0,0,0)#";
this.sessionManagement = "yes";
...
Copy link to clipboard
Copied
Any one have any ideas? Still trying to resolve this.
Copy link to clipboard
Copied
You have to enable session use in the Coldfusion Administrator. In the Memory Variables page, check the boxes
Enable Application Variables |
Enable Session Variables (when unchecked, CSRF protection is disabled)
Copy link to clipboard
Copied
Thanks BKBK. I think that's what I've already done, but I'll check when I get home. I might not have checked both boxes.
Copy link to clipboard
Copied
I confirmed I actually have all three check boxes checked. Cant remember what the other is, and I'm not home right now. But again both of the ones you said to make sure were checked, are.
Anything else you can think of? Thanks for the help!
Copy link to clipboard
Copied
Please confirm by actually opening the Coldfusion Administrator and checking it. Also check that the default values for timeout have sensible values. That is, no 0 times, for example. Then press the button to Submit Changes.
Copy link to clipboard
Copied
Add, if only just for completeness, the attribute applicationtimeout="#CreateTimeSpan(1,0,0,0)#".
Copy link to clipboard
Copied
Ok I'll do both. Wish I had brought my laptop with me to work so I could confirm this now.
Anyway, I screenshot it and add that attribute this afternoon. Thanks again!
Copy link to clipboard
Copied
Here is a screen of my admin and the session var settings I have.
Let me add a screen of the actual error. Maybe its something else.
Copy link to clipboard
Copied
Your description is more detailed, hence much clearer, now. The cause of the problem is that you fail to implement an Application file.
Delete the cfapplication tag from login_process.cfm and save the line
<cfapplication etc. etc.>
as the file Application.cfm
Copy link to clipboard
Copied
I do have an application.cfm file. And the cfapplication is there.
<cfapplication name="login" sessionmanagement="yes" setclientcookies="yes" sessiontimeout="#CreateTimeSpan(0,1,0,0)#" applicationtimeout="#CreateTimeSpan(1,0,0,0)#">
<!--- Now define that this user is logged out by default --->
<CFPARAM NAME="session.allowin" DEFAULT="false" />
<CFPARAM NAME="session.userName" DEFAULT="" />
<cfif session.allowin neq "true">
<cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "login.cfm">
<cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "login_process.cfm">
<cfelse>
<!--- this user is not logged in, alert user and redirect to the login.cfm page --->
<script>
alert("You must login to access this area!");
self.location="login.cfm";
</script>
</cfif>
</cfif>
But I had it named with a lower case application. Not sure if that matters. Nut when I tried to change it, I get a new error. So something changed.
Copy link to clipboard
Copied
Name it Application.cfm not Application.cfc
Copy link to clipboard
Copied
This thread has information that will help someone else in future. If you are satisfied, please mark the post that you consider to be the correct answer. If you find it necessary, add a further explanatory post, and mark that as the answer.
Copy link to clipboard
Copied
Ok so cfm was what I had originally. Still not sure what cause the original error, but in saving my application file as cfc (accidently) then back to cfm....for some reason, not sure why, sublime would default the capital A back to lower case. So that was throwing an error. Had to manually browse to the file and rename it Application.cfm and then open with sublime. Seems to be working now. Maybe sublime issue, althought ive been using sublime for almost 2 years now and had no issues like this before.
Thanks for the help!
Copy link to clipboard
Copied
It's far from sublime I'm afraid. You simply seem to have used the cfapplication tag in Application.cfc. To be clear, the 2 alternatives are:
Application.cfm
<cfapplication name="myApp" applicationtimeout="#CreateTimeSpan(1,0,0,0)#" sessionmanagement="yes" setclientcookies="yes" sessiontimeout="#CreateTimeSpan(0,1,0,0)#">
or else
Application.cfc
<cfcomponent>
<cfscript>
this.name = "myApp";
this.applicationTimeout = "#createTimespan(1,0,0,0)#";
this.sessionManagement = "yes";
this.sessionTimeout = "#createTimeSpan(0,1,0,0)#";
this.setClientCookies = "yes";
</cfscript>
</cfcomponent>
I would again appeal to you to mark off the thread as correct. That serves as a pointer to others with similar issues.
Copy link to clipboard
Copied
No I meant sublime seemed to have an issue saving application.whatever with a capital "A". Not that sublime was the root cause of my session enabled error.
Anyway, thanks for the help and I have marked this as solved and a correct solution.
Copy link to clipboard
Copied
It was too sublime for me to get it, for which I apologize.