how to check end of session with clientcallback page?

B

Bob

Hi,

we have an intranet application where users can join a forum and post a
message. The user first must choose a nickname. There are 'normal' pages and
pages which use the clientcallback method, in order to refresh the list of
active users into a forum.

I use a session variable in this application and i set the timeout = 15
(minutes) in the web.config.

What i try to do is: when the session expires (the user has done nothing for
15' so the value of session("nickname") is then empty), and the user tries
to access any page, anywhere the user is he must be redirected to the start
page for chosing again a nickname. In all pages, i added this code (in
code-behind):

If Session("nickname") = "" Then
Response.Redirect("start.aspx")
End If

This works fine ... except for pages with clientcallback. In this case, the
session never expires, because something is sent to/from the server every 2
seconds.

So, how can i close the session (= how to remove the value of session
variable) when the user stops any activity during 15' while he is on a page
with clientcallback?

Thanks

Bob

See the code in the aspx file:

<script type="text/javascript">
setInterval('refresh();',2000);

function refresh()
{
CallServer('', null);
}

function Retour(mess, context)
{
var obj = document.getElementById("<%= Label1.clientID %>");
obj.innerText = mess;
}

and in code-behind: (part of it)

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
If Session("nickname") = "" Then
Response.Redirect("start.aspx")
Else
Dim cm As ClientScriptManager = Page.ClientScript
Dim cbReference As String
cbReference = cm.GetCallbackEventReference(Me, "arg", _
"Retour", "")
Dim callbackScript As String = ""
callbackScript &= "function CallServer(arg, context)" & _
"{" & cbReference & "; }"
cm.RegisterClientScriptBlock(Me.GetType(), "CallServer", _
callbackScript, True)
End If
End Sub
 
P

Patrice

You could perhaps store the last user (not callback) activity date/time in a
session variable instead of just the nickname. This way you should be able
to don't send the refresh once the timeout is elapsed to let the session die
(or you could force the session expiration when the first callback wihtout
recent user activity occurs).

(basically this is you that handles the session expiration).
 
B

bruce barker

if you are using cookie based sessions, client callbacks do not update the
session timer on the client, as the cookie is not updated and the client will
stop sending it after the timeout.

-- bruce (sqlwork.com)
 
B

Bob

Hi thanks for replying..

i added this in web.config: <sessionState mode="InProc" timeout="15"
cookieless="false">

As test, i started a page with client callback and waited 15'. After that i
tried to navigate to another page and, instead of being redirected to
start.aspx, i accessed that another page. When i do the same test but
starting from a 'normal' page (without client callback), i'm redirected to
start.aspx.
So, unless i do something wrong or i forgot to do something, the cookie
based sessions doesn't work either ...
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top