470,612 Members | 2,471 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,612 developers. It's quick & easy.

Handling session timeout exception

Hello,

Is there any way I can intercept the session timeout exception, and
1) Run some code routine, ie log the error and it's context
2) Show nicer output to the user

Please do not suggest to increase the session timeout value, or write a code
that doesn't loop. No fools here. There are possible contexts where I want
to keep the session timeout reasonably low, but need to log the occasions,
when it's hit, to rearchitecture those parts of the application.

Thanks for valuable tips,

Pavils Jurjans
Apr 2 '07 #1
5 17248
Not sure why do you want log sessions timeout.
For me the best way scenario is to redirect back to login or to "Your
session has expired" page. I have code like that
If( Session["loggedin"] == null ) Response.Redirect("You login expired");
and of course as soon as user logged in I would put something into
Session["loggedin"] = 1;

You might find this article
http://www.codeproject.com/useritems/SessionForever.asp helpful.
It lets session to stay alive without increasing session's timeout. It's
going to be alive till user has page from your site open in the browser.

George.

"Pavils Jurjans" <pa****@mailbox.riga.lvwrote in message
news:OU**************@TK2MSFTNGP04.phx.gbl...
Hello,

Is there any way I can intercept the session timeout exception, and
1) Run some code routine, ie log the error and it's context
2) Show nicer output to the user

Please do not suggest to increase the session timeout value, or write a
code that doesn't loop. No fools here. There are possible contexts where I
want to keep the session timeout reasonably low, but need to log the
occasions, when it's hit, to rearchitecture those parts of the
application.

Thanks for valuable tips,

Pavils Jurjans

Apr 2 '07 #2
Well, my bad. I wanted to say I want to intercept request timeout exception.
Sorry for the mixup...
Hello,

Is there any way I can intercept the session timeout exception, and
1) Run some code routine, ie log the error and it's context
2) Show nicer output to the user

Please do not suggest to increase the session timeout value, or write a
code that doesn't loop. No fools here. There are possible contexts where I
want to keep the session timeout reasonably low, but need to log the
occasions, when it's hit, to rearchitecture those parts of the
application.

Apr 2 '07 #3
Ok, I've found out that I can insert something like

<customErrors mode="On" defaultRedirect="CustomErrorPage.aspx">
</customErrors>

in the <system.websection of web.config file. But, it's still not clear
how to detect the type of the error (is it request timeout? is it something
else?), when running the code in CustomErrorPage.aspx, and it would also be
valuable to know in which page the timeout happened.

Thanks for any help!

Pavils
Apr 2 '07 #4

<customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
<error statusCode="statuscode" redirect="url"/>
</customErrors>

Put "408" or the relevant error code in the 'statusCode' attribute.

Apr 3 '07 #5
I prefer to use a generic error page, and redirect from there :

<system.web>
<customErrors mode="On" defaultRedirect="Errors.aspx"/>
</system.web>

And, in errors.aspx :

errors.aspx
-----------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException, HttpException)
Select Case checkException.GetHttpCode
Case 400
errMessage &= "Bad request. The file size is too large."
Case 401
errMessage &= "You are not authorized to view this page."
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" & appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>We're sorry for the inconvenience."
Server.ClearError()
End Sub
</script>
<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true" runat=server/>
<hr>
<p>Return to <a href=http://yourserver.com/>our entry page</a>
</body>
</html>
---------------

Ymmv, of course, and you can add more info to errors.aspx to suit your needs.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaŮol : http://asp.net.do/foros/
===================================
"Latish Sehgal" <la***********@gmail.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
>
<customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
<error statusCode="statuscode" redirect="url"/>
</customErrors>
Put "408" or the relevant error code in the 'statusCode' attribute.

Apr 3 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Gonenc Ercan | last post: by
7 posts views Thread by Nikhil Patel | last post: by
1 post views Thread by Oscar Thornell | last post: by
41 posts views Thread by Jordan | last post: by
2 posts views Thread by tshad | last post: by
20 posts views Thread by Simon Says | last post: by
9 posts views Thread by Josh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.