how to check end of session with clientcallback page?




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

If Session("nickname") = "" Then
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

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?



See the code in the aspx file:

<script type="text/javascript">

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
If Session("nickname") = "" Then
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




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

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 (


Hi thanks for replying..

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

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
So, unless i do something wrong or i forgot to do something, the cookie
based sessions doesn't work either ...


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