Handling session timeout exception

P

Pavils Jurjans

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
 
G

George Ter-Saakov

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

Pavils Jurjans

Well, my bad. I wanted to say I want to intercept request timeout exception.
Sorry for the mixup...
 
P

Pavils Jurjans

Ok, I've found out that I can insert something like

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

in the <system.web> section 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
 
L

Latish Sehgal

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

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

Juan T. Llibre

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.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top