I have a CF application running on CFMX7 that has sessions
enabled:
%26lt;cfapplication name=''myApplication'' applicationTimeout=
''#createTimespan(2,0,0,0)#'' sessionmanagement=''yes''
clientmanagement=''yes'' sessiontimeout=''#CreateTimeSpan(0,1,0,0)#''
setclientcookies=''yes''%26gt;
however, I noticed that the site periodicially purges the
session periodically booting out any logged in users. I also
beleive that the client variables are also dissapearing when this
issue occurs.
How would you as a developer go about debugging this issue?
Thanks for your help.How would you debug this issue?
Check your logs and see if your server isnt rebooting
periodically. The usually the only reason all the sessions would
wipe.How would you debug this issue?
How would you as a developer go about debugging this issue?
By switching from Application.cfm to Application.cfc which
enables fine-grained interaction with the application. For example,
you could use the onSessionStart event to log details about the
beginning of a new session, and onSessionEnd to log details about
the end of the session.
JoeDangelo, the server isn't rebooting. The issue is easily
replicated on my local development machine as well as the
production server.
BKBK, interesting approach... I've never used that tactic
before.
Here is the approach I have taken so far:
I enabled CF Debugging and I noticed that when the session
and client variables dissapear a new ClientURLToken gets created. I
also tested the error in different browsers to just to make sure
that it wasn't a client-side problem. I noticed that I could only
replicate the error in IE 6, IE7, but not FireFox 2.
I then did some research and noted some posts about asp
developers having difficulties with their session cookies
''sticking'' with IE 6 and 7.
I examined my code, and commented out all my session scoped
variables and all my cookie scoped variables. This solved the
problem and I could no longer generate the error. I re-enabled each
session scope variable and the problem stayed away. Eventually I
found the section of code that is causing the problem.
The section that appears to be causing the problem is where a
cfmodule template creates a cookie with a dynamic variable name.
%26lt;cfcookie name=''#Caller.CurrentPageNoExt#_#tableID#_hide''
value=''no'' expires=''never''%26gt;
This cookie is also referenced and modified by javascript:
%26lt;script language=''javascript''%26gt;
function applyCookie#tableID#() {
if ( document.getElementById('#tableID#').style.display ==
'none') {
document.cookie =
'#UCase(Caller.CurrentPageNoExt)#_#UCase(tableID)#_HIDE = yes;
path=/'
} else {
document.cookie =
'#UCase(Caller.CurrentPageNoExt)#_#UCase(tableID)#_HIDE = no;
path=/'
}
}
%26lt;/script%26gt;
Apparently IE has difficulty somewhere here and purges the
client (cookie) scope. I haven't quite resolved the issue yet, but
at least I know have a place to start.
name=''#Caller.CurrentPageNoExt#_#tableID#_hide''
That likely means you are dynamically assigning distinct
names to cookies. Your application may perhaps have exceeded the
number of cookies allowed per server/domain.
What is the maximum number of cookies you can have per
server/domain? Is this a browser specific setting or something
controlable via ColdFusion?
If I am hitting the maximum number of cookies, perhaps I
should save this particular variable in the Session scope instead
of its own cookie. Although I dont think Javascript will be able to
access that variable if it isn't its own cookie.
After some searches on google, it looks like IE may only be
able to store 20 cookies or so, so I beleive that my templates that
continue to add new cookies ''push'' out the CFID and CFTOKEN cookies
thus logging out the user.
I was hoping to be able to use JavaScript to be able to write
dynamic cookies for me, but instead I'll need to store the dynamic
variables in the session scope.
Henweigh99 wrote:
%26gt; After some searches on google, it looks like IE may only
be able to store 20
%26gt; cookies or so, so I beleive that my templates that
continue to add new cookies
%26gt; ''push'' out the CFID and CFTOKEN cookies thus logging out
the user.
%26gt;
%26gt; I was hoping to be able to use JavaScript to be able to
write dynamic cookies
%26gt; for me, but instead I'll need to store the dynamic
variables in the session
%26gt; scope.
%26gt;
Just to make sure you understand your options for this
decision. Yes,
you can only have 20 or so cookies, but these cookies can
contain more
then one name|value pair. Each cookies can hold several
thousand
characters (4KB IIRC). It takes more work, to pre- and
post-process the
values into and out of a cookie, but it is not difficult work
to add
several values together.
I don't think you can store a structure in a cookie, but you
can store a list, right? Is that how you would recommend storing
multiple name/value pairs?
i.e. ''VariableA,1,VariableB,2,VariableC,3,etc...''
Henweigh99 wrote:
'Is that how you would recommend storing multiple name/value
pairs?
i.e. ''VariableA,1,VariableB,2,VariableC,3,etc...'''
Exactly. You could use wddx/xml if you have the characters to
burn for
the verbose descriptions or you can simply do lists, I
usually use
different characters for between the names and values and
between the
name/value sets.
i.e. variableA=1,VariableB=2,VariableC=3,ect...
OR
i.e. variableA,1|VariableB,2|VariableC,3|ect...
OR
any combo of characters to designate the list.
Either way it is fairly easy to parse these in both JavaScipt
and CFML
code to maximize the use of the available cookies. Just be
aware there
is a maximum cookie size as well, so don't go overboard.
Excellent! Thanks Ian. I really like your idea of using two
sets of delimiters in the cookie value. I'll give it a try this
afternoon and post both the CF code and the JavaScript for future
reference.
Here's what I did:
Instead of creating a cookie with a dual delimiter list I
decided I would simplify it by only storing the values that should
be hidden when the page loads.
So when the page first loads I enable the cookie if it
doesn't exist
%26lt;cfparam name=''COOKIE.HIDDENTABLES'' default=''''%26gt;
Then the Javascript that sets the cookie values (and reads
the cookie values). Note the 2nd function below uses some functions
that came with the CFMLjsLibrary.js file which IMO has been a
lifesaver when it comes to JavaScript functions.
// getCookie function taken from
http://www.w3schools.com/js/js_cookies.asp
function getCookie(c_name) {
if ( document.cookie.length %26gt; 0 ) {
c_start = document.cookie.indexOf(c_name + ''='')
if (c_start!=-1) {
c_start = c_start + c_name.length + 1
c_end = document.cookie.indexOf('';'',c_start)
if (c_end == -1) c_end = document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ''''
}
// this function will look for the hidden table in the
variable list and update it appropriately (add it, delete it)
function applyCookie#tableID#() {
// lets see if this table is already in the hidden list
var theCookie = getCookie('HIDDENTABLES');
var listPosition =
listfindnocase(theCookie,'#Caller.CurrentPageNoExt#_#tableID#');
// if the table is now hidden, lets save this state in the
cookie variable
if ( document.getElementById('#tableID#').style.display ==
'none') {
// only make the change if listPosition is 0
if ( listPosition == 0 ) {
document.cookie = 'HIDDENTABLES = ' +
listappend(theCookie,'#Caller.CurrentPageNoExt#_#tableID#') + ';
path=/';
}
} else {
// the table is visible, we need to remove the current table
from the list
if ( listPosition != 0 ) {
var listWithoutCurrentTable =
listdeleteat(theCookie,listPosition);
document.cookie = 'HIDDENTABLES = ' +
listWithoutCurrentTable + '; path=/';
}
}
}
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment