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
Patrice - 05 Dec 2007 16:46 GMT
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).
--
Patrice
> Hi,
>
[quoted text clipped - 62 lines]
> End If
> End Sub
bruce barker - 05 Dec 2007 17:19 GMT
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)
> Hi,
>
[quoted text clipped - 62 lines]
> End If
> End Sub
Bob - 05 Dec 2007 20:43 GMT
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
> 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
[quoted text clipped - 78 lines]
>> End If
>> End Sub
Bob - 06 Dec 2007 21:59 GMT
Hi Bruce,
can you give some comments about my last message, please?
Thanks
> 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
[quoted text clipped - 78 lines]
>> End If
>> End Sub