I've been working on this for a month and I'm stumped.
This is the code to logout...
...that's it (besides some HTML "You've logged out").
This works fine on our DEV & TEST environments, but gets a 500 Error on our PROD environment. Nothing in the error log. I've searched exhaustively and cannot find anything. And we have a System Admin who is difficult..."it's the code."
Thanks in advance.
If you clear the application structure on logout, it will kill app scoped variables for everyone, not just the current user. Probably not what you intended.
Perhaps wrap with try/catch and see if the 500 still occurs.
Thanks for your explaining the clearing of the application structure, Nic. Unfortunately I am in one of these controlled PROD environments and it will take a minimum of 4 weeks to do a release to PROD.
I have tried isolating the StructClear as such...
<cfset strCleared = 'None'>
<cfif url.clear EQ 'session'>
<cfset strCleared = 'Session'>
<cfelseif url.clear EQ 'application'>
<cfset strCleared = 'Application'>
<cfoutput>#EncodeForHTML(strCleared)#</cfoutput> has been cleared.
...and running each of these...
...and still getting a 500 error for each. Again, happens only on PROD. Works fine on DEV & TEST.
I'm guessing it's either a server (IIS or CF Admin) setting that is causing this error (as the logout.cfm and application.cfm codes are the same on each environment), but unable to replicate this error on DEV or TEST.
Any other ideas?
I remember a number of years ago it was documented to not call structClear(session). That may have changed since CF9 or whenever that was. What are you trying to accomplish? I'd imagine ending the session in Application.cfc might be more what you are looking for. In your onRequestStart you could look for a URL param or template path, and then just call onSessionEnd().
I'm just trying to do a basic logout...which can be accomplished using a structClear(session). The other structClear(application) was left over from the previous developer...not exactly sure what his reasoning was and I have reservations on removing it (fearing it might impact the app somewhere else).
Thank you for your suggestion on ending the session in the Application.cfm file. But I'm concerned that if structClear(session) does not work on PROD (but works on DEV & TEST), then I might have the same problem when implementing your suggestion. That is, I'm wondering if a setting is not letting me clear/end the session properly on PROD.
I think it's a terrible idea to clear the application scope whenever a user logs out. This is just asking for trouble. You might want to investigate why that was put into place so you can get rid of it. I'm not at all surprised that you're getting 500 errors when you do that repeatedly in a production environment.
Nic may also be right about it being a bad idea to just call structClear with the session scope as well, and his suggestion to handle this another way sounds good to me.
Dave Watts, Fig Leaf Software
You might also want to take a look at the logs to see what exception was thrown.
I agree with Dave - if you do a structClear(application) it is going to cause exceptions in a production environment -- the reason for this is that the application scope is shared among all users/requests for the application. So if one request clears the application scope, and another request is concurrently executing it will have expected that the application variables are defined, but since they are not (due to the structClear) it will throw an exception.
Given this, it is likely that when you look at the logs it will say the reason for the 500 exception was application.SomeVariableName is undefined.
Thank you all for your inputs...I greatly appreciate it!
I did try having a couple of persons logging in simultaneously to our DEV environment and then try logging out...was able to log out with no problem. So not sure if it is the structClear(application) that is causing my problem on PROD (albeit makes sense from your details).
Also if the structClear(application) is the culprit, then I should not be getting a 500 error when running logout.cfm?clear=session which executes only structClear(session)....see code above. Executing the structClear(session) generates the 500 error only on PROD, but not on DEV nor TEST environments.
Will implement your suggestions, but hoping someone might have a simpler flip-the-setting on IIS or CF Admin.
The 500 error means that something is wrong with the webserver, but the webserver cannot be specific about what the error is.
Clearing the application scope, as has already been pointed out, ruins the application scope for everyone, not just the user logging out.
As Nic suggested, place the code in question between CFTRY/CFCATCH tags to see if that will shed light on this issue.
<cfdump var="#cfcatch#" />
There is an error going on; we've been notified. We apologise for any inconvenience.<cfabort />
^ _ ^
Finally figured this out...just one of those weird non-logical flukes.
Basically, it was a corrupt directory. We noticed that we would get 500 errors on even basic HTML pages. Deleting and re-creating the directory didn't work. So we changed the directory name from "logout" to "logout2" and voila...that worked!
Hope this might help others down the road.
Thanks for everyone's assistance with this!